错误:液体语法错误:未知标签——变量范围?

Jus*_* L. 2 scope templating liquid jekyll

我试图根据帖子的类别确定为 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 %}
Run Code Online (Sandbox Code Playgroud)

所以{% card_class %}抛出一个错误。是否超出范围?有没有办法将该值放入类属性中?

Dav*_*uel 5

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

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