Set variable in jinja

前端 未结 3 508
你的背包
你的背包 2020-12-04 06:15

I would like to know how can I set a variable with another variable in jinja. I will explain, I have got a submenu and I would like show which link is active. I tried this:<

相关标签:
3条回答
  • 2020-12-04 06:33

    {{ }} tells the template to print the value, this won't work in expressions like you're trying to do. Instead, use the {% set %} template tag and then assign the value the same way you would in normal python code.

    {% set testing = 'it worked' %}
    {% set another = testing %}
    {{ another }}
    

    Result:

    it worked
    
    0 讨论(0)
  • 2020-12-04 06:37

    Nice shorthand for Multiple variable assignments

    {% set label_cls, field_cls = "col-md-7", "col-md-3" %}
    
    0 讨论(0)
  • 2020-12-04 06:43

    Just Set it up like this

    {% set active_link = recordtype -%}
    
    0 讨论(0)
提交回复
热议问题