Search code examples
pythongoogle-app-enginejinja2

Passing variable to a macro in Jinja2


I have made some small macro that I am using to display text line and label for it:

{% macro input(name, text, help_text, value="", input_type) -%}
    <label for="id_{{name}}">{{text}}<span class="right">{{help_text}}</span></label>
    <input id="id_{{name}}" name="{{name}}" value="{{value}}" type="{{input_type}}" />
{{%- endmacro %}

The problem is when I call jinja2 macro:

{{input("username", "Korisničko ime:", "Pomoć", {{value_username}}, "text")}

I can't get it to work when I call input with {{value_username}} as parameter, I always get an error.

Do you know any solution how can I call {{value_username}} as parameter.


Solution

  • I believe

    {{ input("username", "Korisničko ime:", "Pomoć", value_username, "text") }}
    

    should work