Sorry for the double message, but I've managed to build an Extension
that supports footnotes. This solution is *almost* exactly as I would
like it, but it's not quite there. Again, I appreciate any help you
all could offer.

Syntax:

    {% set notes = [] %}
    ...
    {% footnote notes %}
    This is footnote 1!
    {% endfootnote %}
    ...
    {% footnote notes %}
    This is footnote 2!
    {% endfootnote %}
    ...
    <ol>
    {% for x in notes %}
      <li>{{ x }}<li>
    {% endfor %}
    </ol>

Output:

    ...
    [1]
    ...
    [2]
    ...
    1. This is footnote 1!
    2. This is footnote 2!

---

As you can probably tell, I pass the 'notes' list to my extension,
parse the body of the tag, and return the result as a CallBlock, with
the following callback function:

    def _callback(self, args, caller):
        rv = caller()
        args.append(rv)
        return '[%s]' % str(len(args))

Instead of my last two questions, I ask these instead:

1. Is this a safe thing to do in Jinja2? Will I improperly change
anything in the global state or cause some other sort of problem? And,
would this break down when serving multiple requests? (I don't think
so, but I can't be sure.)

2. Is there any way to avoid explicitly passing 'notes' to the
'footnote' tag?

Thanks to Simon for helping me create this first solution, and thanks
again to you all for taking the time to read this.

On Mar 16, 3:04 pm, AKP <[email protected]> wrote:
> This is definitely better than what I had before, and it seems to work
> fairly well. Thank you! But I have two follow-up questions:
>
> 1) Is there any way to define a footnote using tags instead? It seems
> that this would involve much more work, but given that I'll be calling
> several filters in each of my footnotes, I'd like to have the
> convenience of using something like the Django version I described
> earlier.
>
> 2) When you say this can be "wrapped in an object," what sort of
> object do you mean? Do you mean an Extension, or something else? I'm
> still a bit of a Jinja2 novice, so I'm not sure how to proceed here.
>
> Thanks again.
>
> On Mar 16, 6:43 am, Simon Sapin <[email protected]> wrote:
>
>
>
>
>
>
>
> > Le 16/03/2012 08:47, AKP a crit :
>
> > >      ... foo foo {% footnote %}This is a footnote{% endfootnote %} foo
> > > foo ...
> > >      ... bar bar {% footnote %}This is another footnote{% endfootnote
> > > %} bar bar ...
> > >      ...
> > >      ...
> > >      {% all_footnotes %}
>
> > Hi,
>
> > A "low-tech" solution (unested):
>
> > {% set notes = [] %}
> > foo foo {{ notes.append('footnote text') or '[%d]' % len(notes) }}
>
> > ...
> > {% for i, text in enumerate(notes, 1) %}
> > {{ '[%d] %s' % (i, text) }}
> > {% endfor %}
>
> > If this works, it can be wrapped in an object with nice methods and all
> > that.
>
> > Regards,
> > --
> > Simon Sapin

-- 
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.

Reply via email to