The SO link didn't work: http://stackoverflow.com/q/30275557/518169
On Saturday, May 16, 2015 at 10:47:04 PM UTC+2, Zsolt Ero wrote:
>
> Hi,
>
> I've asked this question on SO, but got no answer so far, so I thought I
> should ask it here as well:
>
>
> I would like to implement similar functionality to Django template's
> custom tags in Jinja.
>
> In Django templates, to have a server-side function return a string and
> have it inserted to a template, you can do something as simple as this:
>
> from django import template
>
> register = template.Library()
> @register.inclusion_tag('app/gallery.html')def get_gallery(active=None):
> ### do complex server side things, etc.
>
> context_dict = {
> ...
> }
> return context_dict
>
> Now, calling this is as simple as
>
> {% load app_tags %}{% get_gallery 'home' %}
>
> This seems clear and simple enough for me.
>
> Now my question: even after reading through all parts of the Jinja2
> documentation, I do not see how a similar functionality should be
> implemented in Jinja. I've seen that Jinja supports macros, calls, imports,
> custom tests, custom filters, but I cannot see anything related to defining
> custom tags with arbitrary server-side Python code.
>
> The closest I've seen is custom filters, but that has a weird syntax when
> used for tag-like purposes: to call tag(param1, param2), you'd need to
> write param1|tag(param2). Also, I don't see how it can be used for
> parameter-less functions.
>
> There is also the whole extension support, but that seems overly
> complicated with the simplest example
> <http://jinja.pocoo.org/docs/dev/extensions/#example-extension> taking up
> 56 lines of code in the doc.
>
> Can you explain how do you solve this problem, both in standalone Jinja2
> environment (think static site generation), and under the new Django
> versions (1.8+)?
>
--
You received this message because you are subscribed to the Google Groups
"pocoo-libs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pocoo-libs.
For more options, visit https://groups.google.com/d/optout.