Hi,
I’m trying to implement an image slider / carousel. I’m wondering if the best approach is to use Page Resources or to use an approach like this example whereby the slide data is listed as yaml files under a particular folder (eg slides
) under the data
folder.
I attempted unsuccessfully to follow the example here in this Stackoverflow post.
This is how my content is set up
content
|--> index.md
|--> images/
|--> slide1.jpg
|--> slide2.jpg
|--> slide3.jpg
The front matter of my _index.mg is:
resources:
- name: "slide1"
src: "images/slide1.jpg"
- name: "slide2"
src: "images/slide2.jpg"
- name: "slide3"
src: "images/slide3.jpg"
And my home page template code is:
{{ with .Resources.ByType "image" }}
<div class="slider">
{{ range . }}
<div class='slider-item'>
<img src="{{ .RelPermalink }}" />
</div>
{{ end }}
</div>
{{ end }}
I’ve also tried with no success:
{{ with .Site.GetPage "section" "images" }}
<h2>{{ .Title }}</h2>
{{ $resources := .Resources.ByType "image"}}
{{ range $resources }}
{{ with . }}
<div class='slider-item'>
<img src="{{ .RelPermalink }}">
</div>
{{ end }}
{{ end }}
{{ end }}
I would like to understand why this approach isn’t working before abandoning to use the yaml file approach in the Moodle example above.
Any ideas and pointers would be greatly appreciated. Thank you.