I'm new to Pelican. I'm structuring my site so that I have 2 categories: Blog and Projects. I have 3 menu buttons: Home, Blog, and Projects. I'm trying to edit my base.html
template file so that the Blog button is active if I'm in blog/
or any subdirectory thereof, and the Projects button is active if I'm in projects/
or any subdirectory thereof. If I had a variable accessible in base.html
that gives me the relative URL of the current page, I could split it by /
and get first directory in the path. I've searched around and I can't seem to find a variable for the relative URL of the current page. Is there either a built-in variable or a way for me to make a custom one for what I'm looking for?
As I am also new to pelican, please take the following advice with a grain of salt.
This variable will give you the name of the current file, as stated in the documentation:
{{ output_file }}
For example: When generating menu items for my pages, I can check against the "save_as" property of the page to highlight the exact corresponding menu item:
{% if output_file == p.save_as %}active{% endif %}
But in your case it should be e.g. sufficent to check it the current page is an article at all (assuming that "Blog" contains all of your articles) to highlight the blog menu item. For example by checking if the variable "article" is present:
{% if article %}class="active"{% endif %}
If your projects are made of "pages", simply check against the primary variable of those content type:
{% if page %}class="active"{% endif %}
For the home page, categories, archives etc. one can check the content of "page_name":
{% if page_name == 'index' %}class="active"{% endif %}
© 2022 - 2024 — McMap. All rights reserved.
if page_name
is exactly what I needed! – Simonne