Ok, I've fixed it using kwargs (although it's more verbose than its 
equivalente in Django templates).

Filter:

@contextfilter
def render(context, value, **kwargs):
    """
    Renders the filtered value as a string template, using the context
    and environment of the caller template.
    """
    if kwargs:
        kwargs.update(context)
        ctx = kwargs
    else:
        ctx = context

    #we render the string as its own template
    mini_template = _environment.from_string(value)
    return mini_template.render(ctx)


Usage:

{% for user in list_of_users %}
    {{ greetings[user.locale]|render(user=user) }}
{% endfor %}


Thank you anyway, and please tell me if there is a way to avoid using 
kwargs each time (I've hundreds of template files to update and test!)


-- 
You received this message because you are subscribed to the Google Groups 
"pocoo-libs" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/pocoo-libs/-/sTE0d0g6wQAJ.
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