2017-06-18 81 views
0

我想在YAML中分組一些變量,但我無法在HTML中顯示它們。我需要以某種方式將變量分組。所以,我有這樣的一個數據文件(facultate.yml):Jekyll YAML數據文件變量分組

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> 

而且我無法從顯示materiepdf變量的內容facultate.yml。我嘗試了在其他for循環內嵌套{% for item in sem %}的不同方法。

回答

0

嘗試建立你陽明這樣的:

- 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