I have an articles
folder containing directories to articles.
Is there a way to iterate over these folders and display their names?
{{ range readDir "/content/articles" }}
{{ .Name }}
{{ end }}
The path can be either /content/articles
or content/articles
; the leading /
is irrelevant, as the path is relative to the project root.
References:
1 Like
Thanks! Is there a way to include links to the articles? There is an index.md
file per article folder.
I think I completely misunderstood your question.
Do you want a list page, showing all articles, grouped by the folder in which they reside?
If your file structure is like this:
content/
βββ articles
βββ article-1
β βββ index.md
βββ article-2
β βββ index.md
βββ article-3
βββ index.md
Create layouts/articles/list.html:
{{ define "main" }}
{{ .Content }}
{{ range .RegularPages }}
<h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
<p>{{ .Summary }}</p>
{{ if .Truncated }}
<p><a href="{{ .RelPermalink }}">Continue reading...</a></p>
{{ end }}
{{ end }}
{{ end }}
This assumes you have layouts/_default/baseof.html with a βmainβ block.
2 Likes
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.