2017-01-29 2 views
1
를 사용하여 YAML를 정렬하는 방법

I가 내가 지킬에 alphabetically를 정렬하려고 다음 YML 코드 : 나는 무엇이 필요합니까지킬 액체

<h4>Built With</h4> 
    <ul class="list-unstyled list-inline list-responsibilities"> 
     {% for item in page.builtWith %} 
     <li>{{ item }}</li> 
     {% endfor %} 
    </ul> 

: 여기

layout: project 
title: Home renovation 
link: http://urlgoeshere.com  
builtWith: 
    - Concrete 
    - Glass 
    - Brick 
    - Dirt 

내 템플릿 코드 for 루프를 추가하여 builtWith 항목을 alphabetically으로 정렬 하시겠습니까?

감사합니다. Liquid Warning: Liquid syntax error (line 24): Expected end_of_string but found pipe in "item in page.builtWith | sort" :

답변

1

먼저 변수에 할당해야하기 때문에 작동하지 않습니다 단지 sort 태그를 사용하여, 최신 지킬 버전에서이

{% assign sorted = (page.builtWith | sort) %} 
{% for item in sorted %} 
+0

가, 감사합니다! –

+0

괄호'('')는 Liquid에서 아무 것도하지 않고이 스 니펫에서 제거 할 수 있습니다. –

0

보십시오.

최신 버전을 사용하지 않는 경우 sort을 동일한 행에 추가 할 수 있습니다.

assignsort 태그를 사용하여 안전 :

<h4>Built With</h4> 
<ul class="list-unstyled list-inline list-responsibilities"> 
{% assign sorted = page.builtWith | sort %} 
{% for item in sorted %} 
<li>{{ item }}</li> 
{% endfor %} 
</ul> 

출력 : 완벽하게 작동

Built With 

    Brick 
    Concrete 
    Dirt 
    Glass 
관련 문제