QQCif's Frozen Zone

Nunjucks 变量名冲突

By QQCif

footer.html

{% macro footer(footer='') %}
{{ footer }}
{% endmacro %}

Wrong:

base.html

{% import "base/header.html" as header %}
{% import "base/footer.html" as footer %}
<body>
  {{ header.header(headerTag=headerTag) }}
  {% block content %}{% endblock content %}
  {{ footer.footer(footer=footer) }}
</body>

data.json

{
  "footer": "just a footer"
}

Correct:

base.html

{% import "base/header.html" as header %}
{% import "base/footer.html" as footer %}
<body>
  {{ header.header(headerTag=headerTag) }}
  {% block content %}{% endblock content %}
  {{ footer.footer(footer=another_footer) }}
</body>

data.json

{
  "another_footer": "just a footer"
}

render出来一直是null,最后换了变量名字就好了。