Customizing Nikola

This “blog” is written using Restructured Text and generated by Nikola. Simple customizations to Nikola are done by modifying files in files/assets/. The files in the files directory are moved verbatim into the output.

The CSS file files/assets/css/custom.css is loaded by the default theme, so simple customizations go there.

The files for the theme, set in the file, are also copied into the assets directory, as documented in the theme reference. Nikola has an interesting theme system, where a theme can have a parent theme. The files from the parent theme are used, unless the current theme defines the same file.

The base.tmpl file is where the html pages are defined, then the other specialized templates fill in the details.

To get information from the specific templates, like the post.tmpl, into the base, we can put a block in base.tmpl, and then set the values in the block in post.tmpl.

In base.tmpl:

<%block name="extra_information"></%block>

In post.tmpl:

<%block name="extra_information">
% if post.meta('use_extra_data'):
   <h2>  We have extra data!! </h2>
   Doing some special stuff here.
% endif

The data in post.meta comes from the meta data in the post file:

.. use_extra_data: Yes!

Something that tripped me up, is that the if test in the block above is testing if the string exists, not if it is equal to True.

The main reason I was interested in this was to customize on a post-by-post basis.