Read the docs, searched on here = still confused about page bundles.
Can someone help a noob like me with a few code examples?
If I have this in my content folder. How would I get a list of all my-post titles and any images connected with the posts? Do I need to put something special in my-post/_index.md?
post
my-post
_index.md
my-post.png
my-post-2.md
my-post-3.md
_index.md
Looking for this output in layout/posts/single.html
Title: my-post
img: my-post.png
How would this change if I include a leaf bundle that is not headless. How do I
now get a list of all my-post titles with images? Do I need to put something special in my-post/_index.md or my-post-4/index.md?
post
my-post
_index.md
my-post.png
my-post-2.md
my-post-3.md
my-post-4
index.md
my-post-4.jpg
_index.md
{{- range where .Pages "Section" "post" }}
{{ .Title }}
{{- with .Resources.ByType "image" }}
{{- range . }}
{{ .Title }}
{{- end }}
{{- end }}
{{- end }}
Would give this output:
Post 3
img-1.jpg
img-2.jpg
img-3.jpg
Post 2
img-1.jpg
img-2.jpg
Post 1
img-1.jpg
What happens when you mix a regular content folder with a branch or leaf bundle? So imagine you have lots of posts that have no images, and a select few that do. Creating folders for everything seems overkill so you might do this instead:
How do you range through these examples? Or is mixing like this not good practice? Better to just stick images in /static/ or in /assets/? If so, how would you then call the images?
Will only βdo stuffβ with your images if they exist for a given page bundle. So it would allow you to mix non-bundles, branch bundles, and leaf bundles. Try it out and see.
Iβd recommend browsing the available themes, then when you spot one where you like the way they handle images, go to itβs git repo and explore the template code to see how they did it.