passing a variable into a jinja import or include from a parent html file

前端 未结 2 617
陌清茗
陌清茗 2021-02-07 14:41

The scenario would be:

\"you have a variable called person which contains a number of fields like name, address, etc which you want to pass to a partial piece of html\"

2条回答
  •  青春惊慌失措
    2021-02-07 15:10

    This complements MatToufoutu's answer.

    Environment globals are always available in macros, but context variables are not. To have the context available in an imported macro, you have to use with context when importing, e.g.:

    {% from "your_macros.html" import your_macro with context %}
    

提交回复
热议问题