Hi, I want to create a website that is organized like so:
Hero section
Subsection
Subsection
Image
Image
Subsection
Image
Image
Image
Subsection
Subsection
Image
Image
Subsection
Image
Image
Image
Subsection
Subsection
Image
Image
Subsection
Image
Image
Image
The way the images are organised needs to be easily modifiable, the way way came to mind to achieve this is by representing every section as a directory, and every image as a webp.
So far I have the following code:
{{ range readDir "assets" }}
<section>
<h2>{{ .Name }}</h2>
<div>
{{ range HELP: need to read the subdirectory of the subdir of assets }}
<div>
Here I will loop over each image within the subdir of the subdir of assets, and display it.
<div>
{{ end }}
</div>
</section>
{{ end }}
layouts/_default/home.html (assumes you are using base/block model)
{{ define "main" }}
{{ .Content }}
{{ with site.GetPage "/home" }}
{{ partial "inline/walk-home-sections.html" .Sections }}
{{ end }}
{{ end }}
{{ define "partials/inline/walk-home-sections.html" }}
{{ range .ByWeight }}
<h2>{{ .Title }}</h2>
{{ .Content }}
{{ range .Resources.ByType "image" }}
{{ with .Process "resize 200x" }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ end }}
{{ end }}
{{ with .Sections }}
{{ partial "inline/walk-home-sections.html" . }}
{{ end }}
{{ end }}
{{ end }}
Example:
git clone --single-branch -b hugo-forum-topic-47521 https://github.com/jmooring/hugo-testing hugo-forum-topic-47521
cd hugo-forum-topic-47521
hugo server