How does the routing in templates work?

I am trying to design my own theme starting from blank. The test site builds fine and is indeed empty but functional.

I however fail to understand how the routine in themes work. Specifically, my problem is that I do not see where the main skeleton for the final web page is - that one that will build <header>, <body>, etc. I expected to find there the logic of switching between views: what to parse when looking at the home page, what at a blog entry, what at a standalone page, etc.

To take the example of this starter theme, I see, but it is just the definition of one of the main blocks. There are other such definitions in for instance.

Where do I code the logic/decision to use a specific template file? (one of the several with the definition of main)

I expect that some “routing” (not dynamic one - a routing that is then compiled into a set of pages with links to other pages) must be defined somewhere where you say that the page / is generated from <something> and a page /blog/hello-world is generated from <something else>.

You come from the wrong side at the issue :slight_smile: Hugo has it’s own rules about templates and has a “lookup order” for templates. There are sections (folders in /content) and layouts (frontmatter configuration) and list pages and single pages… Maybe read the docs about this and start here:

1 Like

Thank you very much - this is the documentation I was looking for. I managed to build a pair of index.html (the template) and (the content that work).

I have the feeling that how one approaches these files (content vs templates) for the “structural files” (that is everything outside content that is added, such as posts) really depends on whether this is a one-shot kind of site (in which case the content part could go into the template one), or something intended to be reused (in which case `index.for instance makes sense as it will change).

The worst feeling is that I know there is a lot of power in Hugo but the documentation i sometimes hard to navigate despite being very complete. This makes me think that a “tutorial” section (and how-to) with content from contributors (simple users such as myself) could be worthwhile.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.