2017-03-17 1 views
1

현재 URL 섹션에 페이지를 나열하려고합니다. {{ range .Section }} 유효한 코드가없는 때문에 null을 반환하지만현재 섹션의 페이지를 나열하는 방법

  • 는 현재 제

{{ range $value := .Site.Sections }} 

    {{ range .Section }} 

     {{ range $value.Pages }} 
      <ul> 
       <li>{{ .Title }}</li> 
      </ul> 
     {{ end }} 

    {{ end }} 

{{ end }} 

에서 현재 제

  • 목록 페이지에 모든 섹션
  • 제한 범위를 가져옵니다.

    올바른 방법은 무엇입니까?

    https://gohugo.io/templates/variables/

  • 답변

    2

    당신은 where function를 사용하여 섹션별로 .Site.Pages를 필터링 할 필요가있다. 이것을 시도해보십시오 :

    <ul> 
    {{ range where .Site.Pages "Section" .Section }} 
        <li>{{ .Title }}</li> 
    {{ end }} 
    </ul> 
    

    빈 목록을 피하려면 변수에 섹션 페이지 조각을 저장하고 ul 태그를 출력하기 전에 길이를 확인하십시오.

    {{ $sectionPages := where .Site.Pages "Section" .Section }} 
    {{ if ge (len $sectionPages) 1 }} 
        <ul> 
        {{ range $sectionPages }} 
         <li>{{ .Title }}</li> 
        {{ end }} 
        </ul> 
    {{ end }} 
    
    +0

    당신은 당신이 도울 수있을 것이라고 생각하십니까 : https://stackoverflow.com/questions/46848467/hugo-error-calling-where-cant-evaluate-the-array-by-no-match -argument-or-more – JamesG

    관련 문제