<li><p><aclass="github-button"href="https://github.com/terminal-labs/lektor-jinja-content"data-icon="octicon-star"data-size="large"data-show-count="true"aria-label="Star lektor-jinja-content on GitHub"target="_blank">Star</a></p></li>
<p>This is a Lektor plugin that allows you to render Jinja2 inside your content fields that are string-like. For example, this means that inside your content fields that are of type string or Markdown, you can write Jinja logic, and access Lektor's <ahref="https://www.getlektor.com/docs/templates/#template-context"rel="nofollow">Template Context</a>, and has access to all normal Jinja filters, including those provided by <ahref="https://github.com/terminal-labs/lektor-slugify"rel="nofollow">other plugins</a>. In a Markdown field (or other field that is rendered - like <ahref="https://github.com/fschulze/lektor-rst"rel="nofollow">rst</a>), the <strong>Jinja is processed first</strong>, then the formatting processor.</p>
<p>You can set and use Jinja variables, but they will only have meaning within their field that is being rendered.</p>
<p>With this plugin, you'll have to make sure the content that is rendered <strong>is valid Jinja</strong>. Jinja syntax erros will throw an exception. Don't forget about the handy <code>{% raw %} {% endraw %}</code> tags if you want content that is not valid Jinja.</p>
<p><strong>N.B.</strong> Using this plugin is rendering many more items with Jinja, and your build process will slow down as a result. As an early benchmark and anecdote, my small website's build time rose from 4.89s to 5.39s even while I actually had no Jinja-Content that needed rendering. I plan on adding the ability to configure this plugin later so that you don't have to run <em>everything</em> through Jinja if you don't want to.</p>
<h2>Examples</h2>
<p>Querying context: <code>{{ site.get('/').title }}</code> or <code>{{ this.path }}</code></p>
<prelang="jinja"><spanclass="x">`link text <</span><spanclass="cp">{{</span><spanclass="nv">this</span><spanclass="o">|</span><spanclass="nf">url</span><spanclass="cp">}}</span><spanclass="x">>`_</span>
<p>Try running the <ahref="https://github.com/terminal-labs/lektor-jinja-content/blob/master/tests/demo-project/"rel="nofollow">test site</a> for more examples.</p>
<h2>Possible future of this plugin.</h2>
<p>This Plugin opens the door to some pretty powerful and pretty funky functionality. Here's some food for though:</p>
<ul>
<li>Currently every every string-like field in <code>_data</code> and <code>_blocks</code> is processed, even things like <code>_slug</code> and <code>_template</code>. Can these other things be used?</li>
<li><ahref="https://github.com/lektor/lektor/issues/541"rel="nofollow">Some people want to be able to include markdown in content files / declarations</a>. This plugin might pave the way toward that with <ahref="https://github.com/terminal-labs/lektor-jinja-content/issues/3"rel="nofollow">includes and extends</a>.</li>
Please enable JavaScript to view the <ahref="https://disqus.com/?ref_noscript"
rel="nofollow">comments powered by Disqus.</a>
</noscript>
</div>
</div>
</div>
</div>
</div>
</div>
<divclass="bottomsummary">
<divclass="container">
</div>
</div>
<footer>
<divclass="container">
<divclass="row">
<divclass="col-sm-4 icon-bar">
<ahref="https://github.com/lektor/lektor/"title="Lektor on GitHub"
><iclass="fa fa-github"></i></a>
<ahref="https://github.com/lektor/lektor/issues/"title="Report Issues for Lektor"
><iclass="fa fa-bug"></i></a>
<ahref="https://twitter.com/getlektor"title="Find Lektor on Twitter"
><iclass="fa fa-twitter"></i></a>
<ahref="https://gitter.im/lektor/lektor"title="Chat on Gitter"
><iclass="fa fa-comment"></i></a>
<ahref="https://github.com/lektor/lektor-website/tree/master/content/plugins/lektor-jinja-content/contents.lr"title="View source for this page"><iclass="fa fa-code"></i></a>
</div>
<divclass="col-sm-8">
<ahref="../../license/">License & Copyright</a> •
<ahref="../../contact/">Contact</a> •
Made with <iclass="fa fa-fw fa-heart"title="Heart"><spanhidden>Heart</span></i> in Carinthia