我试图根据帖子的类别确定为 div 提供哪个 css 类,但我创建的变量上不断收到 Error: Liquid syntax error: Unknown tag
.
{% for post in site.posts %}
<!-- Figuring out which css class to give the cards -->
{% assign card_class = "" %}
{% if page.category == 'code' %}
{% assign card_class = "card-code" %}
{% else %}
{% assign card_class = "card-general" %}
{% endif %}
<div class="col-1-2">
<div class="paper-card {% card_class %}">
<h3>
<a class="post-link" href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>
</h3>
<p class="post-excerpt"><span class="post-meta">{{ post.date | date: "%b %-d, %Y" }}</span>{{ post.excerpt | strip_html }}</p>
</div>
</div>
{% endfor %}
因此 {% card_class %}
会抛出错误。是否超出范围?有没有办法将该值放入类属性中?
最佳答案
标签语法({% if t in toto %}
或 {% comment %}
)不适合输出。
您需要使用输出语法{{ card_class }}
。
关于scope - 错误: Liquid syntax error: Unknown tag -- variable scope?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35030035/