Skip to content

xhtml im templating

gbin edited this page Aug 13, 2012 · 5 revisions

This feature is available for versions 1.5.1+

Err supports jinja2 templates for xhtml-im.

For the impatients, here is a cookbook.

1. You need to create a "templates" directory in the root of your plugin repo.

2. In there you need to create a template (ending with .html) that inherits from "base" :

example.html

{% extends "base.html" %}
{% block body %}
<div style="font-family: monospace">
<p style='margin-top: 0; margin-bottom: 0; font-weight:bold'>My name is {{name}} and I am BOLD !</p>
</div>
{% endblock %}

3. Adapt your command to use the template by adding the template parameter to the @botcmd decorator with the template filename without .html and change the return type of your command with a dictionary of the variables you want to pass to your template.

plugin.py

@botcmd(template='example')
def test(self, mess, args):
    return {'name': 'gbin'}

4. What ? That's it ! Err will produce an html part for your answer and automagically produce a pure text version of your message for the non-html clients.

5. For more info about what you can do, read this on.

For more information about what html is supported in the messages you can check xep-0071

For more in depth information about templates, please head to Template designer doc

Clone this wiki locally