A theme I am using has a layout/_default/single.html with the following statement:
{{ if <one of a list of specific sections> }}
do something for that section
{{ else }}
{{ .Render "default" }}
{{ end }}
I assume “.Render default” in the end refers to another content view but which one? Isn’t this particular view default/single.html already the default one? The documentation about this topic only contains a trivial example.
It renders the defaultcontent view for a given page.
For example as per the content files that will be outputted as normal pages and their corresponding templates under layouts of the airspace-hugo theme:
content/en/about.md will use layouts/_default/about.html
content/en/contact.md will use layouts/_default/contact.html
content/en/faq.html will use layouts/_default/faq.html
content/en/message_sent.html will use layouts/_default/message_sent.html
content/en/pricing.html will use layouts/_default/pricing.html
content/en/service.html will use layouts/_default/service.html
Basically the .Render function and the content view templates function pretty much the same as partial templates.
This is simply just another way to organize a Hugo project.
Followup question: under which circumstances in your example would layouts/_default/single.html be called?
Basically, now I wonder if this particular template is just silly as I can’t see the else how the single.html layout is called and then finds a default layout foo.html in the else branch, if foo.html was available could have been called directly rather than single.html.
Do you happen to know of a way to print at runtime which layout file has actually been used?
It is always called for single pages. As per its structure in the airspace-hugo theme different HTML is rendered depending on the set conditions.
The aforementioned content views are more like page components that are rendered in their respective pages.
There is a theme component called debugprint that is available here from what I remember it used to print the PATH of the template that was used for each page. However as per its current demo it appears that this is no longer the case.
To clarify: this is looking for a content view template named “default.html”. The word “default” is a literal string; it is not a keyword or token. I do not understand why the theme author included this code without a corresponding template.
git clone --single-branch -b hugo-forum-topic-35507 https://github.com/jmooring/hugo-testing hugo-forum-topic-35507
cd hugo-forum-topic-35507
hugo server