Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pelican Plugin - How to add context variables?

I am making a pelican plugin and I'm having trouble adding variables to the templates.

For example in my plugin's code:

def baz(generator):
    generator.foo = 'bar'

def register():
    signals.generator_init.connect(baz)

And in my templates I have:

<h1>lorem - {{foo}}</h1>

And I would expect lorem - bar to show in the <h1>.

I have been looking at https://github.com/getpelican/pelican/blob/807b3bced38bff7b83a2efa2ce8cda9d644ebad3/pelican/generators.py trying to see how I can add this as an environment variable to no avail. Any help is much appreciated.

like image 831
anthony-dandrea Avatar asked Sep 29 '22 01:09

anthony-dandrea


1 Answers

What I needed was

generator.context['foo'] = 'bar'
like image 157
anthony-dandrea Avatar answered Oct 19 '22 04:10

anthony-dandrea