Do the Anki libraries provide any HTML templating tools?

Do any of the libraries that Anki provides to Python add-ons (anki, aqt, perhaps another) come with the ability to render any HTML template language?

E.g. if EJS

<ul>
  <% users.forEach(function(user){ %>
  <li>Hello, <%= user.name %>.</li>
  <% }); %>
</ul>

then x.render(template, { "users": [User('Foo'), User('Bar')] }) in Python would produce

<ul>
  <li>Hello, Foo.</li>
  <li>Hello, Bar.</li>
</ul>

Are any templating languages or similar alternatives supported?

You can use jinja2 in your add-on. For example:

import pathlib

from jinja2 import Environment, FileSystemLoader, select_autoescape

from ..settings import ADDON_PACKAGE

templates = (pathlib.Path(__file__).parent / "templates").absolute()
env = Environment(loader=FileSystemLoader(templates), autoescape=select_autoescape())


def request_error(event_id):
    template = env.get_template("request_error.html")
    return template.render(
        addon_package=ADDON_PACKAGE,
        event_id=event_id,
    )
3 Likes