【问题标题】:Jekyll Collection FilterJekyll 集合过滤器
【发布时间】:2019-06-04 13:27:55
【问题描述】:

我正在尝试根据使用 where_exp 的 id 从名为“内容”的集合中获取特定项目,但对于我来说,我无法让它工作。代码如下:

过滤器:

{% assign var = site.content | where_exp:"content", "content.id == 'testId'" | first %}

收藏中帖子的主要内容:

---
layout: content
title: "This is the title"
image: "assets/photos/image.jpg"
id: "testId"
---

html:

<img class="full-width-poto" src="{{ var.image }}"> 

我不知道我做错了什么。

注意,我一直在参考这篇文章:Getting a specific item from a collection in Jekyllhttps://riptutorial.com/jekyll/example/28446/accessing-a-specific-collection-item

【问题讨论】:

    标签: jekyll liquid


    【解决方案1】:

    好的,我发现了我的问题,以防万一有人遇到这个问题。出于某种原因,我不能为此使用密钥“id”...它必须为其他内容硬编码。

    我换了“myid”,现在可以正常使用了...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-25
      • 2017-03-09
      • 1970-01-01
      • 1970-01-01
      • 2011-10-27
      • 2017-08-03
      • 1970-01-01
      相关资源
      最近更新 更多