Variable for current page url in pelican patterns

I am new to Pelican. I structure my site, so I have two categories: blog and projects. I have 3 menu buttons: "Home", "Blog" and "Projects". I'm trying to modify the base.html template file so that the Blog button is active if I'm in blog/ or any of its subdirectories, and the Projects button is active if I'm in projects/ or any of its subdirectories, If I have a variable, available in base.html , which gives me the relative URL of the current page, I can split it into / and get the first directory in the path. I searched around and I cannot find a variable for the relative URL of the current page. Is there a built-in variable or a way for me to create a custom one for what I'm looking for?

+6
source share
1 answer

Since I am also new to pelican, consult with salt.

This variable will give you the name of the current file, as indicated in the documentation :

 {{ output_file }} 

For example: when creating menu items for my pages, I can check the "save_as" property on the page to highlight the exact corresponding menu item:

 {% if output_file == p.save_as %}active{% endif %} 

But in your case, it should be, for example, enough to check that the current page is an article in general (assuming that the "Blog" contains all of your articles) to highlight the blog menu item. For example, checking if the variable "article" exists:

 {% if article %}class="active"{% endif %} 

If your projects are made up of β€œpages,” just check them for the primary variable of this content type:

 {% if page %}class="active"{% endif %} 

For homepage, categories, archives, etc. you can check the contents of "page_name":

 {% if page_name == 'index' %}class="active"{% endif %} 
+6
source

Source: https://habr.com/ru/post/1012827/


All Articles