簡體   English   中英

Jekyll Liquid 應為點點,但在“{{(site.tags | sort:0) for tag in sorted_tags }}”中找到了 pipe

[英]Jekyll Liquid Expected dotdot but found pipe in "{{(site.tags | sort:0) for tag in sorted_tags }}"

如果有人可以提供幫助,我的標簽頁的 Jekyll Liquid 問題。 什么是“點點”? Jekyll 構建良好但留下了一個錯誤的語法錯誤。

Liquid Warning: Liquid syntax error (line 2): Expected dotdot but found pipe in "{{(site.tags | sort:0) for tag in sorted_tags }}" in tags.htmlLiquid Warning: Liquid syntax error (line 9): Expected dotdot but found pipe in "{{(site.tags | sort:0) for tag in sorted_tags }}" in tags.html
---
title: Tags
permalink: /tags/
layout: page
excerpt: Sorted article by tags.
---

<div class="archive-tags">
  {% assign sorted_tags = (site.tags | sort:0) for tag in sorted_tags %}
    {% for tag in sorted_tags %}
    {% capture name %}{{ tag | first }}{% endcapture %}
      <a class="tag-item" href="#{{name}}">{{ name }}</a> 
    {%- endfor -%}
  </div>

{% assign sorted_tags = (site.tags | sort:0) for tag in sorted_tags %}
  {% for tag in sorted_tags %}
  {%- capture name -%}{{ tag | first }}{%- endcapture -%}
  <h2 id="{{ name }}">{{ name | upcase }}</h2>
  {%- for post in site.tags[name] -%}
    <article class="post-item" id="results-container">
      <span class="post-item-date">{{ post.date | date: "%b %d, %Y" }}</span>
      <h3 class="post-item-title">
        <a href="{{ post.url }}">{{ post.title | escape }}</a>
      </h3> 
    </article>
  {%- endfor -%}
{%- endfor -%}

感覺我已經接近 Jekyll 建築的解決方案。 根本找不到清除語法錯誤的解決方案。

我認為它不起作用,因為缺少{% endfor %}

嘗試從 sorted_tags 分配中刪除 for 循環部分。

sort 參數的值為 0 表示元素應按相反順序排列。 如果不為 0,則按升序排序。

任務應該有效; 它以相反的順序對所有標簽進行排序,並將它們分配給一個名為 sorted_tags 的新變量。

無論如何,您都可以使用下一行中的變量來遍歷反向排序的標簽。

<div class="archive-tags">
  {% assign sorted_tags = site.tags | sort:0 %}
    {% for tag in sorted_tags %}
    {% capture name %}{{ tag | first }}{% endcapture %}
      <a class="tag-item" href="#{{name}}">{{ name }}</a> 
    {%- endfor -%}
  </div>

{% assign sorted_tags = site.tags | sort:0  %}
  {% for tag in sorted_tags %}
  {%- capture name -%}{{ tag | first }}{%- endcapture -%}
  <h2 id="{{ name }}">{{ name | upcase }}</h2>
  {%- for post in site.tags[name] -%}
    <article class="post-item" id="results-container">
      <span class="post-item-date">{{ post.date | date: "%b %d, %Y" }}</span>
      <h3 class="post-item-title">
        <a href="{{ post.url }}">{{ post.title | escape }}</a>
      </h3> 
    </article>
  {%- endfor -%}
{%- endfor -%}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM