包含模板中的Swig变量

时间:2019-05-28 13:01:53

标签: javascript express swig swig-template

假定有一个Swig模板base.html,该模板的变量为page

<!-- base.html -->
<div {% if page == 'home' %}class="active"{% endif %}>

使用{% include 'components/content.html'}指令(如

)包含模板时
<!-- base.html -->
{% include 'components/content.html'}

page变量在根目录和包含的模板中都可用吗?

<!-- components/content.html -->
<ul>
    {% if page == 'home' %}<li class="home"></li>
    {% else %}
    <li class="other"></li>
    {% endif %}
<ul>

在我的测试中,似乎page变量在所包含的模板中为undefined,因此无法对其进行评估,因此{% if page == 'home' %}将始终被评估为false

0 个答案:

没有答案