模板渲染错误

ami*_*o21 2 html javascript nunjucks

我正在使用 nunjucks 来呈现一些变量:

    <div class="zoomable zoomable-{{ slide.index }}"> << this works

        {% if slide.temp is none %} << this doesn't
            {% include "layouts/"+{{slide.layout}} %} << this doesn't
        {% endif %}

    </div>
Run Code Online (Sandbox Code Playgroud)

当 JS 调用 nunjucks.render 时,出现以下错误:

parseAggregate: expected colon after dict keyinclude

这有两个问题:

  • 它不应该跳过条件,因为该属性temp 不存在。
  • 是不是不让我访问这些slide属性?因为 slide.layout有效

难道我做错了什么?

the*_*ggs 6

我认为你只需要删除curly bracketsie

{% include "layouts/" + slide.layout %}

  • 由于它已经在 nunjucks 方法结构中,因此不需要大括号进行插值。 (2认同)