Search code examples
pelican

How to get the Pelican version number from a template


I would like to add metadata in the HTML output, indicating that the page was generated from Pelican, and adding the Pelican version number. But I don't find how to get this number. I find no Pelican variable to have this information.

Calling the executable seems the only way?

% pelican --version
3.7.1

Solution

  • I do not know if there is a more direct way to accomplish this, but you could add the following code in your configuration file (pelicanconf.py by default):

    from pelican import __version__
    
    PELICAN_VERSION = __version__
    

    Now, you can reference this newly created variable in your HTML templates with Jinja2 syntax like so:

    <p>I am using Pelican {{ PELICAN_VERSION }}.</p>
    

    When you generate the content of your website to get a directory with static files (this is in output/ by default), the content of the variable PELICAN_VERSION will be added like any other variable in your configuration file and you should be good to go.