Page variables in list template via _index.md

Hi y’all.

I am trying to add some content and front matter to a section page on my site and not having any luck. I am following the advice given on the docs here and adding an _index.md file w/in the section’s directory, but I cannot seem to read from it in my _default.html file.

If I try simply printing {{ .Params.somevariable }}, I get nothing.

When I try printing {{ .Content }} I get an error that “Content is not a field of struct type *hugolib.Node”

I have tried v0.16, 0.17, and 0.18.1 all with the same results.

Any advice?

Thanks,
Sam

I think you are confused about the default folder and how to create the templates. If you have a repo, I’m happy to take a look. If you want a default section page, this should actually be under _default/section.html and not _default.html.

oh whoops. yes, i meant default /layouts/_default/list.html.

My content is under content/start and that’s where I’ve put _index.md as well.

The rest of my list template works fine (paginating and whatnot) but I can’t seem to get frontmatter to work.

Thanks!

_index.md it is new feature which works only in the version 0.18. In previous versions, you need to use index.md.

If you want to know the esoteric of work of the _index.md, you need a long time and carefully study the sequence of templates choice for rendering sections.

Very true.

@SamPotasz Did you trying creating the layout at layouts/_default/section.html? If so, are you getting that same issue? Regardless, I believe that it should be cascading down to layouts/_default/list.html if it’s not being picked up at layouts/_default/section.html. Also, are you sure you have the appropriate front matter and source organization for the corresponding _index.md? If you can point me to a repo where you’re housing the templating, that would help considerably. Also, any errors you’re getting logged to the console.

I’d like to help, but I need more to go off of…

Thanks so much, @rdwatters. I came back to the issue this weekend and got it working. I wasn’t understanding which template would be rendered for the section, but now I think I’ve got it!

1 Like