trying to understand pelican themes

I have been reading over the pelican documentation on theming, but I find that it's rather terse with respect to its guidance on working with Jinja filters. I am therefore having trouble just trying to install frankV's 'twenty-pelican-html5up' theme.

FrankV's theme notes a few caveats with regard to the install. I seem to be caught on the second of these caveats (at least for now):

Using a custom jinja filter I determine the type of page and then return the appropriate body class. In code it looks like this:

<body class="{% if page_name %}{{ page_name|sidebar }}{% endif %} loading">

There's a number of different ways to include a custom defined jinja filter in your pelican project. Here's the documentation for it.

And here's the filter code:

def sidebar(value):  
  if value.startswith('archives') or value.startswith('category'):
    return 'right-sidebar'
  elif value == 'index':
    return 'index'
    return 'no-sidebar'

This is where I'm at:

  1. I verify that pelican is working with the default theme
  2. I install the 'twenty' theme (and to do this, it appears i need sudo to install to /usr/local/lib/python2.7/dist-packages/pelican/themes/twenty
  3. I confirm the theme is installed with pelican-themes -l
  4. I attempt to generate my site content using the theme with pelican content -s -t twenty

Here's the hang-up:

CRITICAL: no filter named 'sidebar'

... how do I create the filter?

This article by linkpeek suggests that all I need is:

  1. the filter code (as above)

  2. to register the function in the, such as as (the linkpeek example):

    import sys
    import liblinkpeek
    JINJA_FILTERS = {'linkpeek':liblinkpeek.api_v1}
  3. to "use the new filter in [the] template (again, the linkpeek example):

    <img src="{{|linkpeek(size='500')}}" />

The challenge is that I don't understand the parts!

For the config, here's my problem with the transcription:

import sys    ## What is sys?  
sys.path.append('.')    ## What does it mean to append sys to the current directory?

import sidebar  
JINJA_FILTERS = {'sidebar':????}    ## What goes on the right side of the column and why?  

Then, to use the new filter in the template, do we just rely on FrankV's code (which is located in his base.html)?

<body class="{% if page_name %}{{ page_name|sidebar }}{% endif %} loading">

I had tinkered around a bit following the example from FrankV's file:

from utils import filters  
JINJA_FILTERS = { 'sidebar': filters.sidebar, 'pretty_date': filters.pretty_date }  

... but when I add this to my file, I just get more errors:

Traceback (most recent call last):  
  File "/usr/local/bin/pelican", line 11, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pelican/", line 351, in main
    pelican, settings = get_instance(args)
  File "/usr/local/lib/python2.7/dist-packages/pelican/", line 337, in get_instance
    settings = read_settings(config_file, override=get_config(args))
  File "/usr/local/lib/python2.7/dist-packages/pelican/", line 145, in read_settings
    local_settings = get_settings_from_file(path)
  File "/usr/local/lib/python2.7/dist-packages/pelican/", line 197, in get_settings_from_file
    module = load_source(name, path)
  File "", line 13, in <module>
    from utils import filters
ImportError: No module named utils  

Can anyone help?

View or Post Comments