错误:液体语法错误:未知标记 - 变量范围?

时间:2016-01-27 06:12:13

标签: scope jekyll liquid templating

我试图确定哪个css类根据帖子的类别给出一个div,但我一直在我创建的变量上得到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 %}会抛出错误。它超出了范围吗?有没有办法将这个值放入类属性?

1 个答案:

答案 0 :(得分:3)

标记语法({% if t in toto %}{% comment %})不适合输出。

您需要使用输出语法{{ card_class }}