The homepage (
templates/index.html) is rendered from the template without the need to have a corresponding content file (like
content/index.md). Is this possible for other pages too ?
For example if I want a website like this:
example.com - homepage
example.com/features/ - a feature page
example.com/blog/ - blog with several posts stored in
I’d rather have
content/features.md because the features template would only ever have one piece of content (thus, I’d rather just do its content with Go templating logic within
features.html and skip the
Reading the docs and trying things out, I didn’t get this to work. However, I believe this would be an excellent feature to allow Hugo to be used in sites that are more complex and not pure blogs / newsfeeds.
I was in the same position and luckily the question is already answered.
Check out this awesome @ChrisSLT comment on static page setup:
Read it few times. It is the recipe to robust landing pages on Hugo. I used this technique myself on Code and Send.
My /content/ directory is a mix of (static, landing-page) .html and .md files (articles). I have two taxonomies (don’t know if that’s a right term): /mag/ and /tests/; each is like a separate blog with its own article streams and custom front-matter structure. Also, I have purely static, perfected .html “about” pages coded using one-off responsive CSS. “About” pages are drawing template headers and footers common with other docs. When I update headers or add new meta tag, all my static pages update together with blog pages.
Definitely check out Chris’ post. It’s a must for any Hugo dev.
Best luck and let us know how it goes.
update. pasted the wrong article. It’s #19 by Chris not #18.
@royston thanks !
That is basically really close to what I’m doing right now so looks like I’m on the right track.
I would still prefer to use GO logic right in the content file itself (or just render the template directly without a content file). Not sure why having multiple pages render like the homepage would be a bad thing, but for some reason Hugo has decided not to go that way.
That method still requires that you do:
instead of just:
The good news in that is the
type=something, layout=something1 trick which allows for better organisation of template files. If I understand correctly, no more need to do:
but now I can