This document is a reference about themes. If you want a tutorial, please read Creating a Theme
Themes are located in the
themes folder where Nikola is installed, and in the
themes folder of your site, one folder per theme. The folder name is the theme name.
A Nikola theme consists of the following folders (they are all optional):
output/assetswhen you build the site, and the templates will contain references to them.
If you want to base your theme on other frameworks (or on no framework at all) just remember to put there everything you need for deployment.
- This contains the templates used to generate the pages. While Nikola will use a certain set of template names by default, you can add others for specific parts of your site.
- Nikola tries to be multilingual. This is where you put the strings for your theme so that it can be translated into other languages.
- Files to be compiled into CSS using LESS
- Files to be compiled into CSS using Sass
This mandatory file:
A text file that, on its first line, contains the name of the parent theme. Any resources missing on this theme, will be looked up in the parent theme (and then in the grandparent, etc).
parentis so you don't have to create a full theme each time: just create an empty theme, set the parent, and add the bits you want modified.
I recommend this:
- If your theme uses bootstrap, inherit the
- If your theme uses bootstrap3, inherit the
- If your theme uses Jinja as a template engine, inherit
bootstrap-jinja(available at http://themes.nikola.ralsina.com.ar)
- In any other case, inherit
- If your theme uses bootstrap, inherit the
And these optional files:
- A text file which, on the first line, contains the name of the template engine this theme needs. Currently supported values are "mako" and "jinja".
A text file containing a list of files to be turned into bundles using WebAssets. For example:
This creates a file called "assets/css/all.css" in your output that is the combination of all the other file paths, relative to the output file. This makes the page much more efficient because it avoids multiple connections to the server, at the cost of some extra difficult debugging.
WebAssets supports bundling CSS and JS files.
Templates should use either the bundle or the individual files based on the
use_bundlesvariable, which in turn is set by the
In templates there is a number of files whose name ends in
.tmpl. Those are the theme's page templates. They are done using the Mako or Jinja2 template languages. If you want to do a theme, you should learn one first. What engine is used by the theme is declared in the
The rest of this document explains Mako templates, but Jinja2 is fairly similar.
Mako has a nifty concept of template inheritance. That means that, a template can inherit from another and only change small bits of the output. For example,
base.tmpl defines the whole layout for a page but has only a placeholder for content so
post.tmpl only define the content, and the layout is inherited from
These are the templates that come with the included themes:
This template defines the basic page layout for the site. It's mostly plain HTML but defines a few blocks that can be re-defined by inheriting templates.
It has some separate pieces defined in
base_helper.tmplso they can be easily overriden. For example, the Bootstrap theme adds a
bootstrap_helper.tmpland then uses it to override things defined in base theme's
- Template used to render the multipost indexes. The posts are in a
postsvariable. Some functionality is in the
- This template handles comments. You should probably never touch it :-) It uses a bunch of helper templates, one for each supported comment system:
- These templates help render specific UI items, and can be tweaked as needed.
Template used for image galleries. Interesting data includes:
text: A descriptive text for the gallery.
crumbs: A list of
link, crumbto implement a crumbbar.
folders: A list of folders to implement hierarchical gallery navigation.
enable_comments: To enable/disable comments in galleries.
photo_array: a list of dictionaries, each containing:
url: URL for the full-sized image.
url_thumb: URL for the thumbnail.
title: The title of the image.
size: A dict containing
h, the real size of the thumbnail.
photo_array_json: a JSON dump of photo_array, used in the bootstrap theme by flowr.js
- Template used to display generic lists of links, which it gets in
items, a list of (text, link) elements.
- Template used to display generic lists of posts, which it gets in
- Template used by default for blog posts, gets the data in a
postobject which is an instance of the Post class. Some functionality is in the
- Used for pages that are not part of a blog, usually a cleaner, less intrusive layout than
post.tmpl, but same parameters.
- Used to display code listings.
- Used to display the list of tags and categories.
tag.tmplis used to show the contents of a single tag or category.
- Used to display tag indexes, if
TAG_PAGES_ARE_INDEXESis True. By default, it just inherits
You can add other templates for specific pages, which the user can then use in his
PAGES option in
conf.py. Also, keep in mind that your theme is yours, there is no reason why you would need to maintain the inheritance as it is, or not require whatever data you want.
Also, you can specify a custom template to be used by a post or page via the
template metadata, and custom templates can be added in the
templates/ folder of your site.
Messages and Translations
The included themes are translated into a variety of languages. You can add your own translation at https://www.transifex.com/projects/p/nikola/
If you want to create a theme that has new strings, and you want those strings to be translatable, then your theme will need a custom
If you want to use those CSS extensions, you can — just store your files in the
sass directory of your theme.
In order to have them work, you need to create a list of
.scss/.sass files to compile — the list should be in a file named
targets in the respective directory (
The files listed in the
targets file will be passed to the respective compiler, which you have to install manually (
lessc which comes from the Node.js package named
sass from a Ruby package aptly named
sass). Whatever the compiler outputs will be saved as a CSS file in your rendered site, with the