How to Range List Data with (YAML)


#1

Hi. all. can help me? :grinning:

How to implement List Data on GoHugo. with range? like

/data/features.yml

list:
  - title: features 1
    description: >
     Description 1
    icon: fa-comment
    
  - title: features 2
    description: >
     Description 2
    icon: fa-headphones
    
  - title: features 3
    description: >
     Description 3
    icon: fa-microphone
    
    
  - title: features 4
    description: >
      Description 4  
	icon: fa-comment-o
    
  - title: features 5
    description: >
     Description 5
    icon: fa-comment-o
    
  - title: features 6
    description: >
     Description 6
    icon: fa-comment-o

/themes/layouts/partial/features.html

    {{ range $.Site.Data.features.list }}


    <h3>{{ .Site.Data.features.list.title }}</h3>

    <span>{{ .Site.Data.features.list.icon }}</span>

    <p>{{ .Site.Data.features.list.title }}</p>


    {{end}}

/themes/layouts/index.html

{{ partial "features" . }}

thank you very much, for the hugo community. to my previous question and very helpful to me :beers:


#2

Hello @TIGA_DUA

the problem is how you access the attributes of each list item. When ranging over a list the context a.k.a. the . changes inside the loop.

With each iteration the current list item will be assigned to the . meaning that you can access the attribute of each list item like this:

<h3>{{ .title }}</h3>

#3

Hai, thanks @digitalcraftsman

Its Working but. has the following issues.

[map[title: Features 1 icon: fa-comment description: description 1. ]

And another listโ€ฆ


#4

Is the map separate from the list in your first comment?
range works the same for maps and arrays.


#5

Hai. @digitalcraftsman

already working, thank you for your time. it turns out there is an equation, with features > folders and features > files

:beers: