Specific renderhooks for "type: blabla"

I don’t use archetypes, and type/section/kind either, except for my homepage (/themes/hugo-book/layouts/_default/home.html acting as baseof.html), but I didn’t write Kind:home. I found that particular case either by chance or reading the docu, but haven’t actually understood how the hell Kind/section/type attributes work by default, without stuffing templates/partials full of {{ if }}. I learn by doing, case by case, until it sank.

Here I wanna use “type” to have an image renderhook for the homepage only.

You can also create type/section specific hooks in layouts/[type/section]/_markup, e.g.: layouts/blog/_markup.

so I created /home/drm/WEBSITE/themes/hugo-book/layouts/essai/_markup/render-image.htm with (valid) rubbish (dfsfds sdfds) inside. My `/content/_index.md is

Title: "Homepage"
Type: essai
{{% content intro_en %}}

But it changed nothing to my page. The image should have disappeared.
What did I mess up ?

1 Like

Could you try to change frontmatter things to be lowercases in first, than instead type try layout.

Also, could you see if there is no browser cache issue (try in other browser for example).

I did but the page always changes according to the default hook. type/layout in lower or uppercase changes nothing.

I haven’t checked, but I’m guessing that the home page cannot have a type (or that it does not have any effect). You can probably verify this by setting type on any of the other content pages you have in your site.

Yes !
Should I raise an issue on hugo’s github?

there are templates for the home page!

home.html is a template and uses content/_index.md as source.

home page “kind” is not overridden by frontmatter kind: test - it is always of kind “home”, which makes sense, it is a special kind vs page or index.
home page “type” can be overridden by frontmatter type: test

You can set up a different render-image.html hook in

That will give you the render-hook on any pages, including the homepage you give type: page
Tested it worked.

I added this to my baseof to help test:


A .Template would be useful to have. Template lookup was my only real sticking point when starting with Hugo, it is very flexible but that makes it a little tricky at first.

Ahhh… I understood now !
content/_index.md calls on the shortcode “content”, which is

{{ with .Get 0 | site.GetPage }}{{ .Content }}{{ end }}

While intro.md

 render: false

is rendered first then sent to to the shortcode (or _index.md). So types work on intro.md instead ! Or else, type works with the homepage if I have to change .Content for .RawContent | markdownify so delay the rendering to after its inclusion into _index.md. < or % has no impact.
I just didn’t know how it worked since I knew .RawContent existed… I could have predicted it. I think I confused not building with not rendering. So it was my fault, but it’s fine, I learnt stuff.
Thanks for you time.

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