flask-htmx icon indicating copy to clipboard operation
flask-htmx copied to clipboard

Make the HTMX object available in templates as a global context variable

Open edmondchuc opened this issue 1 year ago • 0 comments

For example:

from flask_htmx import HTMX

htmx = HTMX(app)

Now in Flask's Jinja templates, a htmx variable is available. This is useful for such cases where conditionals are required to render certain blocks of HTML in the Jinja templates.

{% if htmx %}
<div id="app" hx-swap-oob="true">...</div>
{% endif %}

This is useful when paired with using Jinja's include tag and htmx's hx-boost and hx-swap-oob attributes.

edmondchuc avatar Aug 16 '23 10:08 edmondchuc