django-floppyforms
django-floppyforms copied to clipboard
Add Jinja2 support
I would love to help to add jinja2 based templating feature. But in order to do that, I need to understand the structure of _form_config, is there any document about that?
Also, as I can understand, currently floppyforms template tags are putting the _form_config into the template context, which would be an issue for Jinja, since the context is immutable. see http://jinja.pocoo.org/docs/api/#the-context
The context is immutable. Modifications on parent must not happen and modifications on vars are allowed from generated template code only. Template filters and global functions marked as contextfunction()s get the active context passed as first argument and are allowed to access the context read-only.
So, I am thinking of directly attach the _form_config to the form itself, just setattr(form, '_form_config', ...)
. How does it work for you?
Yes adding the _form_config
to the form instance could work, but I think this would not be threadsafe.
I would opt for something differently. I don't know Jinja2 very much, especially not the internals or how to write template tags, but there exist some tags, like the forloop that are adding new variables to the context:
{% for user in users %}
{{ user }} variable is not available outside of the for loop.
{% endfor %}
So there must be a way of adding new variables to the context. In floppyforms the _form_config
is a attribute of the context. I choose to implement it that way, since this makes it impossible to access it in the template directly. With Jinja2 I could imagine putting this into the context as variable directly could work. Like this:
{% form myform using %}
{{ _form_config }} variable is available here.
But shouldn't be used of course ...
{% endform %}
What do you think?
This issue should be re-addressed and get a higher priority since Django 1.8 will support multiple rendering engines. Getting Jinja2 support in would be really cool.
Would it be possible to get an update on this?