2016-02-26 10 views
0

我已经成功地以字母顺序显示液体中的.csv文件中的数据,但我使用的代码仅添加了一个在整个列表的开始处为空的<li>标记。在我看来,“分裂”过滤器负责输出的格式,所以也许有一些东西。使用unorderd列表在液体中按字母顺序排序.csv数据会产生一个空列表元素

这是我在液态代码:

--- 
layout: default 
--- 
{% capture thelistings %} 
    {% for listing in site.data.terminology %} 
    {{ listing.term }}: {{ listing.definition }} 
    {% endfor %} 
{% endcapture %} 
{% assign allsortedlistings = thelistings | split:" " | sort %} 

<ul> 
{% for allterms in allsortedlistings %} 
<li>{{ allterms }}</li> 
{% endfor %} 
</ul> 

这里是该.csv数据文件:

term,definition 
brother,new explanation for one 
aunt,another explanation for two 
uncle,"and last one for three, with the use of comma fin" 
father,this is it 
again,now it is here 
utah,this is a state 
borrow,something from someone 
forbidden,fruit 

,这里是输出列表:

  • 再次:现在在这里
  • 阿姨:另一种解释两
  • 贷:从别人的东西
  • 兄弟:新解释一个
  • 父亲:这是
  • 禁:果
  • 叔叔:和最后一个三,与使用逗号鳍
  • 犹他州的:这是一种状态,我所输出的数据的方式

回答

0

问题骗。在做第一个时{% capture %}你必须格式化你希望输出的数据,在这种情况下,我希望它是一个列表项,所以它应该看起来像这样<li>{{ listing.term }}: {{ listing.definition }}</li>,因此将它包装在<li>元素中,然后将它分配给它如{{ allterms }}里面的<ul>。所以最终的代码将如下所示:

--- 
layout: default 
--- 
{% capture thelistings %} 
    {% for listing in site.data.terminology %} 
    <li>{{ listing.term }}: {{ listing.definition }}</li> 
    {% endfor %} 
{% endcapture %} 
{% assign allsortedlistings = thelistings | split:" " | sort %} 

    <ul> 
{% for allterms in allsortedlistings %} 
     {{ allterms }} 
{% endfor %} 
    </ul> 
相关问题