Add support for macros in templates #625

Closed
wants to merge 1 commit into
from

Projects

None yet

1 participant

@FSX
FSX commented Nov 5, 2012

Support for simple macros (or functions, just took the name from Jinja2) has been added in the template parser. They can be accessed within the file or block they're defined in.

The current implementation it limited and I was thinking of putting the macros in a dictionary and write the contents when a macro is called. Didn't do that yet, because that'll introduce new syntax for calling macros.

Why macros? I'm currently working on an application with a lot of forms and putting the form controls in separate files did seem a bit too much and confusing. It looks more simple like the code example below.

{% autoescape None %}
{% include "../utils.html" %}

<form method="POST" action="{{ action }}">
  {{ hidden_fields(form.xsrf) }}
  {{ field(form.username) }}
  {{ field(form.password) }}
  {{ submit_field(form.submit) }}
</form>

What do you think about this?

@FSX FSX closed this May 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment