facebook/tornado — pull request #625 by FSX (2012-11-05 15:44:23+00:00)
Title: Add support for macros in templates

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" %}

{{ hidden_fields(form.xsrf) }}
{{ field(form.username) }}
{{ field(form.password) }}
{{ submit_field(form.submit) }}

~~~

What do you think about this?