Keats / tera

A template engine for Rust based on Jinja2/Django
http://keats.github.io/tera/
MIT License
3.43k stars 279 forks source link

Is it possible to render 1 specific block in a template? #834

Open rgwood opened 1 year ago

rgwood commented 1 year ago

Hi, thanks for writing+maintaining Tera; it's great!

Given a template like this:

{{ foo }}

{% block bar_block %}
{{ bar }}
{% endblock %}

Is it possible to render just the bar_block block using Tera? From skimming the API docs I don't think it is, but maybe I'm missing something.

The use case I have is an HTMX UI, where it's useful to be able to render parts of a template. Prior art: the jinja2-fragments library, the render_block function in Minijinja.

Keats commented 1 year ago

Not currently but this is something I'm thinking of adding for v2, I'm working on block support for it and will likely do a render_block fn anyway internally so it shouldn't be too hard to expose