0
我正在使用Jekyll構建網站,並試圖在每篇文章的末尾使用Liquid邏輯創建一個'Recent Posts'數組。用!=邏輯過濾Liquid/Jekyll數組?
我想這個數組包含所有帖子,除了您當前所在頁面的帖子。
於是,我開始有:
{% for post in site.posts limit:2 %}
{% if post.title != page.title %}
//render the post
{% endif %}
{% endfor %}
這工作,但我的limit: 2
導致的問題。由於Liquid限制之前的邏輯if
,如果它真的遇到標題等於當前頁面標題的帖子,它將(正確)不會渲染它,但它會認爲限制「滿意」 - 我最終只有1相關崗位而不是2
接下來,我嘗試創建我自己的訊息陣列:
{% assign currentPostTitle = "{{ page.title }}" %}
{% assign allPostsButThisOne = (site.posts | where: "title" != currentPostTitle) %}
{% for post in allPostsButThisOne limit:2 %}
//render the post
{% endfor %}
這不工作,因爲我不能讓where
過濾器接受!=
邏輯。
如何成功解決此問題?
優秀的,這正是我需要的東西 - 一個新的方式來思考解決問題。謝謝! – GloryOfThe80s