Discussion:
Nesting Templates?
bostondevin
2011-03-19 15:29:33 UTC
Permalink
Hi - new to using this and so far it's been pretty great! Very happy
that @index is available, it would be great if $ was available so I
could access things in the parent node from inside a loop, and all the
other crazy things we can do in xml!

How do I apply a template to another template - say I want to have a
wrapper template that I always want to apply to things - is there a
way to do something like this?

tmpl1: "Here is my outer template <div class='wrapper'>{tmpl2}</div>"
tmpl2: "Here is my inner {label}"

Also, if you have any advanced examples i'd be interested
--
You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to json-template+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/json-template?hl=en.
Andy Chu
2011-03-21 04:48:42 UTC
Permalink
Post by bostondevin
Hi - new to using this and so far it's been pretty great! Very happy
could access things in the parent node from inside a loop, and all the
other crazy things we can do in xml!
How do I apply a template to another template - say I want to have a
wrapper template that I always want to apply to things - is there a
way to do something like this?
tmpl1: "Here is my outer template <div class='wrapper'>{tmpl2}</div>"
tmpl2: "Here is my inner {label}"
Also, if you have any advanced examples i'd be interested
This is the subject of this doc/essay:
http://json-template.googlecode.com/svn/trunk/doc/On-Design-Minimalism.html

You can reuse the "outside", aka a common "style" for your pages. Or
you can reuse the "inside", like a widget.

However in the Python version, I subsequently refined these ideas and
built it in more.

To reuse a widget you can use the "template" formatter, and
MakeTemplateGroup. e.g.

{bob|template user-profile}
{john|template user-profile}

"user-profile" being another template. (Now that I realize it,
MakeTemplateGroup should really be make_template_group to follow PEP8
naming...)

For the styles case, you can use expand_with_style. This is a little
more convenient than doing it yourself. You only have one template
dictionary.

The best examples right now are in the unit tests, e.g.
http://code.google.com/p/json-template/source/browse/python/jsontemplate/jsontemplate_unittest.py

It's possible to wire these same patterns into the JS version, or just
do it "manually" as I suggested in the doc.

These are in the latest version that I posted about a week ago to the
downloads section.

Andy
--
You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to json-template+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/json-template?hl=en.
Loading...