feat: render document or fragment
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
<thead>
|
||||
<tr><th>foo</th><th>bar</th><th>baz</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for row in table %}
|
||||
<tr><td>{{ row.foo }}</td><td>{{ row.bar }}</td><td>{{ row.baz }}</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
7
templates/fragment/user/table.html
Normal file
7
templates/fragment/user/table.html
Normal file
@@ -0,0 +1,7 @@
|
||||
<tr><th>name</th><th>email</th></tr>
|
||||
{% for user in users.as_ref().unwrap() %}
|
||||
<tr>
|
||||
<td>{{ user.name }}</td>
|
||||
<td>{{ user.email }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
19
templates/index.html
Normal file
19
templates/index.html
Normal file
@@ -0,0 +1,19 @@
|
||||
{% extends "layout.html" %}
|
||||
|
||||
{% block content %}
|
||||
<hgroup>
|
||||
<h1>Hello htmx!</h1>
|
||||
<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 %}
|
||||
</table>
|
||||
{% endblock %}
|
||||
@@ -9,20 +9,13 @@
|
||||
<script src="/static/js/htmx.min.js"></script>
|
||||
<script src="/static/js/script.js"></script>
|
||||
|
||||
<title>Hello htmx!</title>
|
||||
<title>{% block title %}Hello htmx!{% endblock %}</title>
|
||||
|
||||
{% block head %}{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
<hgroup>
|
||||
<h1>Hello htmx!</h1>
|
||||
<p>A new old way to build web applications</p>
|
||||
</hgroup>
|
||||
|
||||
<table>
|
||||
<tr><td>
|
||||
<button hx-get="/table" hx-target="table" hx-push-url="true">
|
||||
Load data
|
||||
</button>
|
||||
</td></tr>
|
||||
</table>
|
||||
<main id="content">
|
||||
{% block content %}{% endblock %}
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user