<li><p><aclass="github-button"href="https://github.com/skorokithakis/lektor-shortcodes"data-icon="octicon-star"data-size="large"data-show-count="true"aria-label="Star lektor-shortcodes on GitHub"target="_blank">Star</a></p></li>
Lektor Shortcodes<br>=================<br><br>[![PyPI](https://img.shields.io/pypi/v/lektor-shortcodes.svg)](https://pypi.python.org/pypi/lektor-shortcodes)<br><br>The Lektor Shortcodes plugin allows you to use shortcodes (shortcodes are<br>something like custom tags) in your fields (not templates), so your content<br>doesn't have to have repetitive snippets over and over.<br><br>For example, my blog has some specific HTML that I add when I want an image with<br>a border and caption to be displayed. The HTML looks like this:<br><br><br>~~~html<br><div class="alignright"><br><a href="image-large.jpg"><br><img src="image.jpg" /><br><span class="caption">The caption</span><br></a><br></div><br>~~~<br><br>Copy-pasting this every time gets tedious, and I have to search and replace it<br>in all the content files every time I want to make a change. With the<br>shortcodes plugin, this can be written as:<br><br>~~~<br>[% image align=right link="image-large.jpg" image=image.jpg caption="The caption" %]<br>~~~<br><br>Much easier, cleaner and less repetitive.<br><br><br>Installation<br>------------<br><br>To install the plugin, just add `lektor-shortcodes` to your plugins from the<br>command line:<br><br>~~~<br>lektor plugins add lektor-shortcodes<br>~~~<br><br><br>Usage<br>-----<br><br>Using the plugin is simple. Just create a config file called `shortcodes.ini` in<br>your `configs` directory and specify some shortcode templates. The templates are<br>full Jinja templates, although (due to some limitations of ini files) they need<br>to be on one line.<br><br>For instance, for the example above, the config file could be:<br><br>~~~ini<br>[global]<br>image = '<div class="align{{ align }}">{% if link %}<a href="{{ link }}"{% if not link.startswith("http") %} data-lightbox="gallery"{% endif %}>{% endif %}<img src="{{ image }}">{% if link %}</a>{% endif %}{% if caption %}<span class="caption">{{ caption }}</span>{% endif %}</div>'<br>~~~<br><br>This will allow you to use shortcodes with optional arguments, like so:<br><br>~~~<br># An image with no caption or link:<br>[% image align=right image=hello.jpg %]<br><br><br># An image with a link:<br>[% image align=right link=http://www.example.com image=hello.jpg %]<br><br># Link and caption:<br>[% image align=right link=http://www.example.com image=hello.jpg caption="Hello!" %]<br>~~~<br><br>Shortcodes defined within the section named `global` will be processed<br>automatically inside any of your site’s Markdown content. It is also possible to<br>define shortcodes which are only expanded when the Jinja2 template for a page<br>explicitly requests it. Shortcodes defined in any section not named `global`<br>will only be applied when the template passed the content through a Jinja2<br>filter named `shortcode`. For example, if your HTML template references a field<br>called `body`, you may request expanding shortcodes defined within the<br>`body-only` section of your config file, like so:<br><br>~~~<br>{{ body|shortcodes(section="body-only") }}<br>~~~<br><br>This will enable all shortcodes from the specified section, in addition to all<br>globally defined shortcodes. If no section is specified, the filter defaults to<br>the section named `main`.<br><br><br>Miscellanea<br>-----------<br><br>If you find a bug or have a feature request, please open an issue or file a PR.<br>Thanks!<br>
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-shortcodes/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