【问题标题】:access name of yaml items (pointer reference ?) in liquid template [duplicate]液体模板中yaml项目的访问名称(指针引用?)[重复]
【发布时间】:2016-11-12 16:52:41
【问题描述】:

假设我有这样的 yaml 数据:

  fruit:
    - apple: 
      - color: "green"
      - taste: "bitter"
    - banana: 
      - color: "yellow"
      - taste: "sweet"

我想解析列表以获得打印结果:

apple

banana

有没有办法编写一个液体模板来实现上述结果,无需修改我的 yaml 数据(因为当然可以通过将其更改为 name:"banana" 等来修复它。 ..)

{% for item in page.fruit %}
{{ item.?????? }}
{% endfor %}

干杯

【问题讨论】:

  • 对,实际上所有这些概念、语义和符号:哈希、{{ page.fruit }} 输出中的 => 等等,都是直接从 Ruby 继承的。但是,AFAIK,这在 Jekyll 或 Liquid 的文档中没有明确说明!
  • 同意。这就是为什么将您的问题作为重复的would be good,将“重复”视为问题的替代版本/措辞。

标签: yaml jekyll


【解决方案1】:

好的,我找到了解决方案 in the OP here。正如这家伙所指出的那样,对于这一系列(面向对象?)思想的新手来说,猜测并不是特别容易......

---
layout: default
title: qui l'eut cru ?
permalink: /fruits/
fruit:
  - apple: 
    - color: "green"
    - taste: "bitter"
  - banana: 
    - color: "yellow"
    - taste: "sweet"
---

{% for item in page.fruit %}
{% for browser in item %}
**root of the sublist:** {{browser[0]}}  
**contents of the sublist:** {{browser[1]}}  
{% endfor %}
{% endfor %}

【讨论】:

    猜你喜欢
    • 2014-07-30
    • 1970-01-01
    • 1970-01-01
    • 2021-05-14
    • 2013-01-07
    • 2011-08-22
    • 1970-01-01
    • 2012-02-17
    相关资源
    最近更新 更多