anthony-dandrea
anthony-dandrea

Reputation: 2813

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.

Upvotes: 5

Views: 457

Answers (1)

anthony-dandrea
anthony-dandrea

Reputation: 2813

What I needed was

generator.context['foo'] = 'bar'

Upvotes: 4

Related Questions