hugohugo-theme

Hugo: Override single block in theme layout


I'm using a theme ( https://github.com/frjo/hugo-theme-zen ) which in it's baseof.html has {{- block "head" . }}{{ end }} and this block is not defined in any layout. Now I want to extend the theme by adding content in the head block.

My initial attempt has been to add a new file layouts/_default/list.html to my project which defines the block, however it seems like I override the themes whole list layout ( https://github.com/frjo/hugo-theme-zen/blob/main/layouts/_default/list.html ) instead of only the 'head' block.

How can I add custom html content to the block 'head' in this theme without modifying the code of the theme itself?


Solution

  • Yes, you need to add/override a template that extends "baseof.html" to use {{- block "head" . }}{{ end }}.

    I added the "head" block to make it possible to add things to "" without needing to override "baseof.html".