Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I inspect Pelican variables

Tags:

jinja2

pelican

I'm modifying a Pelican template and I have the code below which adds url every time a page is found. I can see that the p object has the attributes url and title.

However I only knew this because I copied the code from another template shown below. Is there any way to inspect objects in jinja2 or Pelican to understand what information is contained within them?

      {% for p in pages %}
        <h1 class = "sidebar-title">
          <a href="{{ SITEURL }}/{{ p.url }}">
          {{ p.title }}
          </a>
        </h1>

https://github.com/getpelican/pelican-themes/blob/master/backdrop/templates/base.html

<li{% if p == page %} class="active"{% endif %}><a href="{{ SITEURL }}/{{ p.url }}">{{ p.title }}</a></li>
like image 399
canyon289 Avatar asked Jan 21 '26 08:01

canyon289


1 Answers

I am not aware of an official resource explaining all variables, objects, attributes and properties in detail.

But for a start, I think the following start points suffice:

  • Common variables available for the standard templates
  • pelican.contents.py: This is the module which contains (most of) the data structures pelican uses and which are made available in the templates. Have a look for properties (@property, these are functions which act like they are attributes) and attributes. At lines 367ff there are some very simple subclass definitions which could be of use.
  • pelican.writers.py: This module brings together the templating engine jinja2, the templates and the data to be inserted in the templates. Of special interest for you could be lines 138ff, as this seems like a good point to simply insert some small debug prints to see the real data which is present in the data structures.
like image 153
Michael Hoff Avatar answered Jan 23 '26 18:01

Michael Hoff