Package: pelican-jinja2content
Jinja2Content Plugin for PelicanThis plugin allows the use of Jinja2 directives inside your Pelican articles and pages.In this approach, your content isfirstrendered by the Jinja template engine. The result is then passed to the normal Pelican reader as usual. There are two consequences for usage. First, this means the Pelican context and Jinja variablesusually visibleto your article or page template arenotavailable at rendering time. Second, it means that if any of your input content could be parsed as Jinja directives, they will be rendered as such. This is unlikely to happen accidentally, but it’s good to be aware of.All input that needs Pelican variables such asarticle,category, etc., should be put inside yourtheme’stemplating. As such, the main use of this plugin is to automatically generate parts of your articles or pages.Markdown, reStructured Text, and HTML input are all supported. Note that by enabling this plugin, all input files of these file types will be pre-processed with the Jinja renderer. It is not currently supported to selectively enable or disablejinja2contentfor only some of these input sources.ExampleOne usage is to embed repetitive HTML in Markdown articles. Since Markdown doesn’t allow customization of layout, if anything more sophisticated than just displaying an image is necessary, one is forced to embed HTML in Markdown articles (i.e. hard-code<div>tags and then select them from the theme’s CSS). However, withjinja2content, one can do the following:Filemy-cool-article.md# My cool title

My cool content.

{% from 'img_desc.html' import img_desc %}
{{ img_desc("/images/my-cool-image.png",
    "This is a cool tooltip",
    "This is a very cool image.") }}Where fileimg_desc.htmlcontains:{% macro img_desc(src, title='', desc='') -%}
<div class="img-desc">
  <p><img src="{{ src }}" title="{{ title }}"></p>
  {% if desc %}
  <p><em>{{ desc }}</em></p>
  {% endif %}
</div>
{%- endmacro %}The result will be:# My cool title

My cool content.

<div class="img-desc">
  <p><img src="/images/my-cool-image.png" title="This is a cool tooltip"></p>
  <p><em>This is a very cool image.</em></p>
</div>After this, the Markdown will be rendered into HTML and only then the theme’s templates will be applied.In this way, Markdown articles have more control over the content that is passed to the theme’sarticle.htmltemplate, without the need to pollute the Markdown with HTML. Another added benefit is that nowimg_descis reusable across articles.Note that templates rendered withjinja2contentcan contain Markdown as well as HTML, since they are added before the Markdown content is converted to HTML.InstallationThis plugin can be installed via:pip install pelican-jinja2contentConfigurationThis plugin accepts the settingJINJA2CONTENT_TEMPLATESwhich should be set to a list of paths relative toPATH(the main content directory, usually"content").jinja2contentwill look for templates inside these directories, in order. If they are not found in any, the theme’s templates folder is used.ExtendingThis plugin is structured such that it should be quite easy to extend readers for other file types to also render Jinja template logic. It should be sufficient to create a new reader class that inherits from theJinjaContentMixinand then your desired reader class. See class definitions in the source for examples.ContributingContributions are welcome and much appreciated. Every little bit helps. You can contribute by improving the documentation, adding missing features, and fixing bugs. You can also help out by reviewing and commenting onexisting issues.To start contributing to this plugin, review theContributing to Pelicandocumentation, beginning with theContributing Codesection.AcknowledgementsOriginal implementation by @joachimneu and re-worked by @Leonardo.Updated to support reST and HTML input by @micahjsmith.Converted to new plugin format by @justinmayer.Replacespelican-jinja2content, which had become unmaintained.