refactor: render fragment explicitly

Instead of including the template for non-hx-requests, inject the
rendered fragment.
This commit is contained in:
2023-05-10 20:37:27 +02:00
parent 32f5afb10f
commit 4489a8a8e5
2 changed files with 15 additions and 13 deletions

View File

@@ -6,14 +6,16 @@
<p>A new old way to build web applications</p>
</hgroup>
<table>
{% if users.is_some() %}
{% include "fragment/user/table.html" %}
{% else %}
<tr><td>
<button hx-get="/user" hx-target="table" hx-push-url="true">
Load data
</button>
</td></tr>
{% endif %}
{% match fragment %}
{% when Some with (fragment) %}
{{ fragment|safe }}
{% when None %}
<tr><td>
<button hx-get="/user" hx-target="table" hx-push-url="true">
Load data
</button>
</td></tr>
{% endmatch %}
</table>
{% endblock %}