Version: | 7.6.0 |
---|---|
Author: | Roberto Alsina <ralsina@netmanagers.com.ar> |
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):
This is where you would put your CSS, Javascript and image files. It will be copied into output/assets when you build the site, and the templates will contain references to them.
The included themes use Bootstrap and Colorbox so they are in assets, along with CSS files for syntax highligting and reStructuredText, and a minified copy of jQuery.
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 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).
The parent is 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:
And these optional files:
A text file containing a list of files to be turned into bundles using WebAssets. For example:
assets/css/all.css=bootstrap.css,rst.css,code.css,colorbox.css,custom.css
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_bundles variable, which in turn is set by the USE_BUNDLES option.
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 engine file.
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 base.tmpl.
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.tmpl, base_header.tmpl and base_footer.tmpl so they can be easily overriden.
Template used for image galleries. Interesting data includes:
- post: A post object, containing descriptive post.text() for the gallery.
- crumbs: A list of link, crumb to implement breadcrumbs.
- folders: A list of folders to implement hierarchical gallery navigation.
- enable_comments: To enable/disable comments in galleries.
- thumbnail_size: The THUMBNAIL_SIZE option.
- 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 w and h, the real size of the thumbnail.
You can add other templates for specific pages, which the user can then use in his POSTS or 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.
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 messages folder.
Note
The LESS and Sass compilers will be moved to the Plugins Index in Nikola v7.0.0.
If you want to use those CSS extensions, you can — just store your files in the less or sass directory of your theme.
In order to have them work, you need to create a list of .less or .scss/.sass files to compile — the list should be in a file named targets in the respective directory (less/sass).
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 less or 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 .css extension.
Note
Conflicts may occur if you have two files with the same base name but a different extension. Pay attention to how you name your files or your site won’t build! (Nikola will tell you what’s wrong when this happens)