for key, value in foo.iteritems()
I've thought about this -- the easiest way in Python would be to make
use of the "section formatters", which I added pretty recently. They
are just regular formatters, but they can return a list. And they can
be applied to repeated sections.
So if you have:
{ foo: {k1: v1, k2, v2} }
You should be able to do:
{.repeated section foo | pairs}
{@key} {@value}
{.end}
Where "pairs" is a function like this:
def Pairs(data):
result = []
for k, v in data.iteritems():
result.append({'@key': k, '@value': v})
return result
The dictionary node is transformed to a list node right before iteration.
I think this should probably be built in to the python version -- if
it works for you send me a patch.
> And for internationalization, I saw in the previous group posts that it can
> be done through formatters e.g. {foo| Trans}. But usually there are strings
> (not variables) which are required to be translated. Is there any way of
> making that possible?
It depends what your workflow is like. It's hard to think of a scheme
which isn't error prone... the most robust method seems to be to have
a "database" of all strings, but I realize that most web apps don't
have that.
It's easy to parse templates and generate them. In fact I think I
even exposed the parse/tokenizer for the syntax highlighter. So if
you have an English template, you can parse it and pick out the
literal strings, and then translate those strings, and assemble
another template.
I guess this is done at "build time" rather than at template expansion
time -- you have a set of static templates for each language.
Perhaps a way of making this less error prone would be to have some
markers like this
{#trans}This is a string that has a translation{#end}
{#comment} is a comment and will already work. So then your parser
can identify literal strings identified by the template author,
instead of trying to guess at all the string boundaries.
I don't know if there are any better schemes; open to suggestions.
Andy