【发布时间】:2021-12-04 13:39:33
【问题描述】:
我在一个 html 文件中有以下前题:
---
layout: default
title: Fausto Bellino Tasca | Montecito
permalink: "/montecito.html"
imageSet: "montecito"
---
在 html 的正文中,我有以下内容:
{% for image-info in galleries.{{ imageSet }} %}
<li class="splide__slide">
<img src="/images/{{ imageSet }}/{{ image-info.filename }}" alt="{{ image-info.caption }}">
<div class="main-slider-caption">
{{ image-info.caption }}
</div>
</li>
{% endfor %}
img 标记中的 {{ imageSet }} 工作正常,但是当我尝试在 for 循环中使用它时,十一会抛出以下错误:
`TemplateContentRenderError` was thrown
> Having trouble compiling template ./src/montecito.html
`TemplateContentCompileError` was thrown
> illegal tag: {% for image-info in galleries.{{ imageSet }} %}, file:./src/montecito.html, line:11
`ParseError` was thrown
> illegal tag: {% for image-info in galleries.{{ imageSet }} %}
`AssertionError` was thrown:
AssertionError: illegal tag: {% for image-info in galleries.{{ imageSet }} %}
还有额外的错误信息,注意引发错误的液体 js 文件。
当我简单地将 {{ imageSet }} 替换为文本本身时,即在本例中为“montecito”时,它可以正常工作。
欢迎任何想法,因为我有很多看起来像这样的页面,我想用这种外观制作一个短代码并传递到最前面的项目。
谢谢。
【问题讨论】:
-
我找到了答案。在这种情况下,正确的语法是 gallery[imageSet] 而不是 gallery.{{ imageSet }}。
标签: html templates liquid eleventy