From: Fabien Potencier Date: Mon, 15 Oct 2012 07:15:27 +0000 (+0200) Subject: updated macro documentation to warn about a hack that won't work anymore in Twig 2.x X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=a6473b7cfddee17b073d570738289137b9dfeb22;p=web%2Fkonrad%2Ftwig.git updated macro documentation to warn about a hack that won't work anymore in Twig 2.x --- diff --git a/doc/tags/macro.rst b/doc/tags/macro.rst index 3d920e3..155f7fe 100644 --- a/doc/tags/macro.rst +++ b/doc/tags/macro.rst @@ -48,41 +48,33 @@ The macro can then be called at will:

{{ forms.input('password', null, 'password') }}

If macros are defined and used in the same template, you can use the -special ``_self`` variable, without importing them: +special ``_self`` variable to import them: .. code-block:: jinja -

{{ _self.input('username') }}

+ {% import _self as forms %} -When you want to use a macro in another one from the same file, use the ``_self`` -variable: +

{{ forms.input('username') }}

-.. code-block:: jinja +.. warning:: - {% macro input(name, value, type, size) %} - - {% endmacro %} + When you define a macro in the template where you are going to use it, you + might be tempted to call the macro directly via ``_self.input()`` instead + of importing it; even if seems to work, this is just a side-effect of the + current implementation and it won't work anymore in Twig 2.x. - {% macro wrapped_input(name, value, type, size) %} -
- {{ _self.input(name, value, type, size) }} -
- {% endmacro %} - -When the macro is defined in another file, you need to import it: +When you want to use a macro in another macro from the same file, you need to +import it locally: .. code-block:: jinja - {# forms.html #} - {% macro input(name, value, type, size) %} - + {% endmacro %} - {# shortcuts.html #} - {% macro wrapped_input(name, value, type, size) %} - {% import "forms.html" as forms %} + {% import _self as forms %} +
{{ forms.input(name, value, type, size) }}