tera icon indicating copy to clipboard operation
tera copied to clipboard

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

Open rgwood opened this issue 2 years ago • 1 comments

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.

rgwood avatar Jun 13 '23 18:06 rgwood

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

Keats avatar Jun 14 '23 10:06 Keats