I am trying to write a custom theme for Nikola, a static site generator. I have been mostly following their tutorial but have run into a problem. I want to show certain HTML specifically on pages (not on posts) in the spot where the page_header
template hook appears. So I first ran this command:
nikola theme -c page.tmpl
That copies the base theme's page.tmpl file into my custom theme's directory. That file is actually only 1 line long, simply this:
<%inherit file="story.tmpl"/>
So I added a definition for <%block name="page_header"> ... </%block>
. However, the code I defined inside that block does not show up on my pages. Just to make sure I wasn't going crazy, I also defined <%block name="extra_head"> ... </%block>
within that same page.tmpl file, and in that case the code contained therein did show up.
Why would the overridden extra_head
block work while the overridden page_header
block doesn't work within the same template file?
If you are having an issue where the overridden
page_header
block is not showing up but theextra_head
block is, then it is possible that thepage_header
hook is not being used or triggered in the parent template (story.tmpl
) thatpage.tmpl
is inheriting from.See
zzzeek/mako
/doc/build/inheritance.rst
To check that, make sure that
story.tmpl
or any other template that it may inherit from actually uses thepage_header
block. If it does not exist there, then overriding it inpage.tmpl
will not have any effect.Sometimes, there might be multiple layers of template inheritance. Do make sure there is no intermediate template between
page.tmpl
andstory.tmpl
that might be interfering with the blocks.As a test, try to explicitly invoke the
page_header
block withinpage.tmpl
outside of the block definition, like:mako ${self.page_header()}
That should force the rendering of the content of that block, if it is correctly defined.