【问题标题】:Jekyll YAML data file variables groupingJekyll YAML 数据文件变量分组
【发布时间】:2017-06-18 16:54:35
【问题描述】:

我正在尝试在 YAML 中对一些变量进行分组,但我无法在 HTML 中显示它们。

我需要以某种方式对变量进行分组。所以,我在数据文件中有这个(facultate.yml):

an1:
  - sem1:
    - materie: Example 1
      pdf: nimic
    - materie: Example 2
      pdf: nimic
  - sem2:
    - materie: Example 3
      pdf: nimic

an2:
  - sem1:
    - materie: Example 4
      pdf: nimic
  - sem2:
    - materie: Example 5
      pdf: nimic

我在 HTML 文件中有这个:

---
layout: compress
---
<!DOCTYPE html>
<html>
PDF-uri facultate
<br />
<br />{% assign nrani = 0 %}{% for an in site.data.facultate %}{% assign nrani = nrani | plus: 1 %}An: {{ nrani }} {% assign nrsem = 0 %}Sem:{% for sem in an %}{% assign nrsem = nrsem | plus: 1 %}{{ nrsem }} {% endfor %}<br />{% endfor %}
<br />{% for item in sem %}{{ item.materie }}{% endfor %}
</html>

我无法显示来自facultate.ymlmateriepdf 变量的内容。我尝试了不同的方法,例如将 {% for item in sem %} 嵌套在其他 for 循环中。

【问题讨论】:

    标签: markdown jekyll liquid


    【解决方案1】:

    尝试像这样设置你的 yml:

    - an:
      - sem:
        - materie: Example 1
          pdf: nimic
        - materie: Example 2
          pdf: nimic
      - sem:
        - materie: Example 3
          pdf: nimic
    
    - an:
      - sem:
        - materie: Example 4
          pdf: nimic
      - sem:
        - materie: Example 5
          pdf: nimic
    

    【讨论】:

      猜你喜欢
      • 2016-02-19
      • 2013-01-07
      • 2023-03-11
      • 2021-08-21
      • 1970-01-01
      • 2019-01-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多