Pelican Navbar by Page

Authors note: since this post was written, quite a few things have changed. I still vastly prefer static content generation, but have since switched to Hugo.

While it may not be obvious, this site is entirely generated by pelican. This gives a couple nice benefits: Simplicity, Security and a good deal of Customization.

Additionally since it uses Jinja templates, it is something that I am very familiar and comfortable with. Additionally, the blog posts are written in Markdown, which means that between the two things, it is fairly robust and straightforward.

One of the things that I ran into while creating the template that runs this site, was the inability to use something similar to the {% if pg == page %} for custom pages that I have generated.

This is primarily due to the fact that I have a custom index page that is generated using the following format(in

DIRECT_TEMPLATES = ('index', 'tags', 'categories', 'archives', 'landingpage')
INDEX_SAVE_AS = 'blog/index.html'

What I used to solve this was by adding an if statement on the page_name variable inside my template:

<li{% if page_name == 'index' %} class="active"{% endif %}><a href="{{ SITEURL }}/">Home</a></li>
<li{% if page_name == 'blog/index' %} class="active"{% endif %}><a href="{{ SITEURL }}/blog/">Blog</a></li>
Avatar photo James is a security nerd with a technology problem. Follow him on Twitter TwitterTweet