setup htmx to swap (or not) inner html
This commit is contained in:
parent
7815b07f81
commit
bfc2721f28
6 changed files with 23 additions and 9 deletions
|
|
@ -1,10 +1,21 @@
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
use axum::response::{Html, IntoResponse};
|
use axum::{
|
||||||
|
http::HeaderMap,
|
||||||
|
response::{Html, IntoResponse},
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "index.html")]
|
#[template(path = "index.html")]
|
||||||
struct IndexTemplate;
|
struct IndexTemplate;
|
||||||
|
|
||||||
pub async fn home() -> impl IntoResponse {
|
#[derive(Template)]
|
||||||
|
#[template(path = "partials/index.html")]
|
||||||
|
struct IndexPartialTemplate;
|
||||||
|
|
||||||
|
pub async fn home(headers: HeaderMap) -> impl IntoResponse {
|
||||||
|
if headers.contains_key("hx-request") {
|
||||||
|
Html(IndexPartialTemplate.render().unwrap())
|
||||||
|
} else {
|
||||||
Html(IndexTemplate.render().unwrap())
|
Html(IndexTemplate.render().unwrap())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
1
static/vendor/htmx.min.js
vendored
Normal file
1
static/vendor/htmx.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -5,13 +5,16 @@
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link rel="icon" type="image/gif" href="/static/assets/gifs/pcgif.gif" />
|
<link rel="icon" type="image/gif" href="/static/assets/gifs/pcgif.gif" />
|
||||||
<title>Agahnim</title>
|
<title>Agahnim</title>
|
||||||
<link rel="stylesheet" href="/static/style.css">
|
<link rel="stylesheet" href="/static/style.css" />
|
||||||
|
<script src="/static/vendor/htmx.min.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body hx-boost="true" hx-target="#content">
|
||||||
{% include "partials/header.html" %}
|
{% include "partials/header.html" %}
|
||||||
|
|
||||||
|
<main id="content">
|
||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
|
</main>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,5 @@
|
||||||
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>Bonjour</h1>
|
{% include "partials/index.html" %}
|
||||||
<p>Bienvenue sur mon site.</p>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
<header>
|
<header>
|
||||||
<nav>
|
<nav>
|
||||||
<a href="/">Accueil</a>
|
<a href="/">Accueil</a>
|
||||||
<a href="/blog">Blog</a>
|
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
1
templates/partials/index.html
Normal file
1
templates/partials/index.html
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<h1>Bonjour</h1>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue