getnikola / nikola

A static website and blog generator
https://getnikola.com/
MIT License
2.62k stars 450 forks source link

page_header template hook is not activating when set in theme file #3706

Open soapergem opened 1 year ago

soapergem commented 1 year ago

Environment

Python Version: 3.10.7

Nikola Version: 8.2.4

Operating System: Windows 11

Description

I'm new to Nikola and have been simultaneously trying to follow both the Creating a Site (Not a Blog) guide as well as the Creating a Theme guide. I want to be able to override the page_header template hook specifically on my index page, within my custom theme, but am running into a lot of trouble. I based my theme off the default Mako one, per the guide.

The first thing I did was copy the index.tmpl file using nikola theme -c index.tmpl. Then I tried adding the following block definition to it:

<%block name="page_header">
    ${parent.page_header()}
    Test content
</%block>

However, my test content string doesn't show up anywhere when I run nikola build. Is there something I'm missing?

Kwpolska commented 1 year ago

Template hooks are usable only from within plugins. There is a template block for the header, but it’s named extra_header, not page_header.

Also, note that index.tmpl affects blog indexes, it won’t change the index page if you’re going that route. For that, you would need to apply a special template via the PAGES config setting, or override page.tmpl and check if the post variable is the index page.