I have the following working partial to display items on home page:
<div class="section-content">
{{ with .Resources.GetMatch "**.json" }}
{{ $data := .Content | transform.Unmarshal }}
{{ with $data }}
{{ with .items }}
{{ range $index, $element := $data.items }}
<a {{ with $element.url }}href="{{ $element.url | relURL }}"{{ end }} class="project-single">
{{ with $element.featured_image }}<img class="lazyload blur-up" alt="{{ $element.title | markdownify }}" src="{{ . | relURL }}">{{ end }}
<h1><span>{{ $element.title | markdownify }}</span>{{ with $element.subtitle }}<span>{{ $element.subtitle | markdownify }}</span>{{ end }}</h1>
</a>
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
</div>
I would like to add a count of items (number of items) within this partial. I don’t know how to use len function len $items
as I am not a coder.
Help will be much appreciated.
The structure of the json file is as follows:
"items" : [
{
"title" : "Title",
"content" : "Bla Bla",
"items" : [
{
"description": "Bla bla",
"subtitle": "",
"url": "/dossiers/item1/",
"title": "",
"featured_image": "item1.png"
},
{
"description": "",
"subtitle": "",
"url": "/dossiers/item2/",
"title": "",
"featured_image": "/dossiers/item2.png"
}
}
]