Hi everyone. I apologise if this is an uninformed question. I’ve done my best to read the docs, watch the tutorials and search the forums. I can’t figure it out.
{{ .Content }} isn’t appearing inside my list template. It appears fine in my single template.
My list.html sits inside layouts/_default/ This is its content.
<ul class="range">
{{ range .Pages }}
<li>
<a href="{{ .URL }}">{{ .Title }}</a>
</li>
{{ end }}
</ul>
The list templates render the ranges perfectly, with all the requested page content but without the {{ .Content }} content.
I have content appropriately placed in my content directory to show up at the top of these list pages. I’m not sure how to make it show up. Is anyone able to offer a suggestion?
Why are you rendering your content on the list page? List pages aren’t meant for that. While I may not be very experienced in Hugo, according to my understanding, list pages only serve as sort of reference pages for single pages. Therefore that may be why you’re unable to render {{ .Content }} there.
Could you also explain what you’re aiming to do?
Say, I have a list of posts. At the top of that list, I’d like to insert some {{ .Content }} that I can populate via markdown from inside the Content directory.
The purpose of that content might be to pre-announce what is in the list.
Oh that is what you meant to do. Hugo already provides a function to do so, {{ .Summary }}. Read the docs here: Content Summaries. There’s also a helpful example to do exactly what you want.
Thank you, though I’m afraid {{ .Summary }} is generated per post. I’m attempting to insert arbitrary {{ .Content }} above those posts (not to mention, insert front-matter).
I have been experimenting with the naming of that file while attempting to troubleshoot this. I’ve put it back to _index.md, and I’m still seeing the above behaviour.
Being a list/branch, it rightly shows the child pages. I just can’t get it to respect the front matter or {{ .Content }} defined in _index.md.
edit: If I delete_index.md it renders the same thing. I think the issue is that the markdown _index file is being ignored.
How odd. You may need to share your site code for us to be able to help you better. If you are unable to share the full site, a smaller one with just enough layouts and dummy content that reproduces the error would help.