github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/flosch/pongo2.v3/template_tests/macro.tpl (about)

     1  Begin
     2  {% macro greetings(to, from=simple.name, name2="guest") %}
     3  Greetings to {{ to }} from {{ from }}. Howdy, {% if name2 == "guest" %}anonymous guest{% else %}{{ name2 }}{% endif %}!
     4  {% endmacro %}
     5  {{ greetings() }}
     6  {{ greetings(10) }}
     7  {{ greetings("john") }}
     8  {{ greetings("john", "michelle") }}
     9  {{ greetings("john", "michelle", "johann") }}
    10  {{ greetings("john", "michelle", "johann", "foobar") }}
    11  
    12  {% macro test2(loop, value) %}map[{{ loop.Counter0 }}] = {{ value }}{% endmacro %}
    13  {% for item in simple.misc_list %}
    14  {{ test2(forloop, item) }}{% endfor %}
    15  
    16  issue #39 (deactivate auto-escape of macros)
    17  {% macro html_test(name) %}
    18  <p>Hello {{ name }}.</p>
    19  {% endmacro %}
    20  {{ html_test("Max") }}
    21  
    22  Importing macros
    23  {% import "macro.helper" imported_macro, imported_macro as renamed_macro, imported_macro as html_test %}
    24  {{ imported_macro("User1") }}
    25  {{ renamed_macro("User2") }}
    26  {{ html_test("Max") }}
    27  
    28  Chaining macros{% import "macro2.helper" greeter_macro %}
    29  {{ greeter_macro() }}
    30  End