Skip to content

Commit

Permalink
removed leftover of 93c4406 and made some language improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobion committed May 16, 2012
1 parent 7f06c12 commit b692268
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions doc/templates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -414,33 +414,32 @@ Macros
------

Macros are comparable with functions in regular programming languages. They
are useful to put often used HTML idioms into reusable elements to not repeat
yourself.
are useful to reuse often used HTML fragments to not repeat yourself.

A macro is defined via the :doc:`macro<tags/macro>` tag. Here is a small
example of a macro that renders a form element:
A macro is defined via the :doc:`macro<tags/macro>` tag. Here is a small example
(subsequently called ``forms.html``) of a macro that renders a form element:

.. code-block:: jinja
{% macro input(name, value, type, size) %}
<input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" />
{% endmacro %}
Macros can be defined in any template, and need to be "imported" before being
used via the :doc:`import<tags/import>` tag:
Macros can be defined in any template, and need to be "imported" via the
:doc:`import<tags/import>` tag before being used:

.. code-block:: jinja
{% import "forms.html" as forms %}
<p>{{ forms.input('username') }}</p>
Alternatively you can import names from the template into the current
namespace via the :doc:`from<tags/from>` tag:
Alternatively, you can import individual macro names from a template into the
current namespace via the :doc:`from<tags/from>` tag and optionally alias them:

.. code-block:: jinja
{% from 'forms.html' import input as input_field, textarea %}
{% from 'forms.html' import input as input_field %}
<dl>
<dt>Username</dt>
Expand Down

0 comments on commit b692268

Please sign in to comment.