Fwd: [flask] Jinja and expression statements
- From:
- Joshua Bronson
- Date:
- 2011-03-26 @ 05:04
[I just replied-all with the below and Librelist again did not recognize me
as an allowed sender, so I'm forwarding. This is the second time this has
happened, and both times I've CC'd the list. When I email To:
flask@librelist.com directly it works fine. Librelist bug?]
---------- Forwarded message ----------
From: Joshua Bronson <jabronson@gmail.com>
Date: Sat, Mar 26, 2011 at 12:57 AM
Subject: Re: [flask] Jinja and expression statements
To: Nicolas Clairon <clairon@gmail.com>
Cc: flask@librelist.com
app.jinja_env.add_extension('jinja2.ext.do')
I figured this out from
https://github.com/mitsuhiko/jinja2/blob/master/jinja2/environment.py#L283
On Fri, Mar 25, 2011 at 10:18 AM, Nicolas Clairon <clairon@gmail.com> wrote:
> Thank, I missed the registered extensions part :/
>
> In order to not erase the existing app.jinja_env, I updated it like this:
>
> app.jinja_env.extensions.update(Environment(extensions=['jinja2.ext.do
> ']).extensions)
>
> It works but this seems hacky. Is there a more elegant/official
> solution to do this ?
>
> On Fri, Mar 25, 2011 at 3:01 PM, Joshua Bronson <jabronson@gmail.com>
> wrote:
> > Hey Nicolas,
> > On Fri, Mar 25, 2011 at 9:42 AM, Nicolas Clairon <clairon@gmail.com>
> wrote:
> >>
> >> Hi Flaskers,
> >>
> >> I went on a issue recently with using the expression statement. The
> >> following code will through a TemplateSyntaxError:
> >>
> >> {% set new_stuff = [] %}
> >> {% for staff in stuff %}
> >> {% do new_stuff.append(staff) %}
> >> {% endfor %}
> >>
> >> TemplateSyntaxError: Encountered unknown tag 'do'. Jinja was looking
> >> for the following tags: 'endfor' or 'else'. The innermost block that
> >> needs to be closed is 'for'.
> >>
> >> However, replacing {% do new_stuff.append(staff) %} by
> >> {{new_stuff.append(staff)}} works (but display None).
> >>
> >> Any ideas ?
> >>
> >> N.
> >
> > I found some related docs
> > at http://jinja.pocoo.org/docs/extensions/#expression-statement. Have
> you
> > read those? According
> > to http://jinja.pocoo.org/docs/extensions/#adding-extensions, you need
> to do
> > something like
> > jinja_env = Environment(extensions=['jinja2.ext.do'])
> > in order to be able to use the "do" tag.
> > HTH,
> > Josh
>