On Sun, Sep 30, 2012 at 8:38 PM, Marten Lehmann <[email protected]> wrote: > How is it supposed to be done in Jinja2? At least the documentation doesn't > mention an else-directive for the for-loop. An outer if-condition would > probably work, but wouldn't look very elegant.
It is mentioned in the docs here: http://jinja.pocoo.org/docs/templates/#for "If no iteration took place because the sequence was empty or the filtering removed all the items from the sequence you can render a replacement block by using else" This is working for me: >>> t = jinja2.Template("{% for x in xs %}* {{ x }}\n{% else %}Nothing found.{% >>> endfor %}") >>> t.render(xs=[1,2,3]) u'* 1\n* 2\n* 3\n' >>> t.render(xs=[]) u'Nothing found.' -Steve -- You received this message because you are subscribed to the Google Groups "pocoo-libs" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pocoo-libs?hl=en.
