Simon Willison’s Weblog

Subscribe
Atom feed for templates

6 items tagged “templates”

2024

MiniJinja: Learnings from Building a Template Engine in Rust (via) Armin Ronacher's MiniJinja is his re-implemenation of the Python Jinja2 (originally built by Armin) templating language in Rust.

It's nearly three years old now and, in Armin's words, "it's at almost feature parity with Jinja2 and quite enjoyable to use".

The WebAssembly compiled demo in the MiniJinja Playground is fun to try out. It includes the ability to output instructions, so you can see how this:

<ul>
  {%- for item in nav %}
    <li>{{ item.title }}</a>
  {%- endfor %}
</ul>

Becomes this:

0   EmitRaw "<ul>"
1   Lookup  "nav"
2   PushLoop    1
3   Iterate 11
4   StoreLocal  "item"
5   EmitRaw "\n <li>"
6   Lookup  "item"
7   GetAttr "title"
8   Emit    
9   EmitRaw "</a>"
10  Jump    3
11  PopFrame    
12  EmitRaw "\n</ul>"

# 27th August 2024, 3:47 pm / armin-ronacher, templates, rust, webassembly, jinja

2019

datasette-template-sql (via) New Datasette plugin, celebrating the new ability in Datasette 0.32 to have asynchronous custom template functions in Jinja (which was previously blocked by the need to support Python 3.5). The plugin adds a sql() function which can be used to execute SQL queries that are embedded directly in custom templates.

# 15th November 2019, 12:59 am / projects, sql, templates, datasette, jinja

2007

Seasoning Templates. “Designing a template language is a lot like seasoning a dish; there’s a whole range of tastes out there.”

# 19th July 2007, 6:04 pm / django, templates, jacob-kaplan-moss

Logic in Templates. I don’t think it would hurt Django to have a bit more support for conditional logic in templates, but I wouldn’t go as far as supporting the ability to call Python functions directly.

# 19th July 2007, 8:35 am / templates, logic, christopher-lenz, python, django

Naming URL patterns (via) You can now apply a name to a URL pattern in Django development version, which makes the {% url %} template tag far more useful.

# 10th April 2007, 12:19 am / django, templates

Django templates in Venus. It’s nice to see the Django template system being used outside the context of the overall framework.

# 14th February 2007, 11:22 pm / django, venus, templates