File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -118,6 +118,9 @@ async fn get_index(HxBoosted(boosted): HxBoosted) -> impl IntoResponse {
118118
119119### Example: Responders
120120
121+ We can trigger any event being listened to by the DOM using an [ htmx
122+ trigger] ( https://htmx.org/attributes/hx-trigger/ ) header.
123+
121124``` rust
122125use axum_htmx :: HxResponseTrigger ;
123126
@@ -130,6 +133,33 @@ async fn index() -> (&'static str, HxResponseTrigger) {
130133}
131134```
132135
136+ ...` htmx ` even allow arbitrary data to be sent along with the event, which we
137+ can use via the ` serde ` feature flag and the ` HxEvent ` type.
138+
139+ ``` rust
140+ use axum_htmx :: HxEvent ;
141+
142+ // Note that we are using `HxResponseTrigger` from the `axum_htmx::serde` module
143+ // instead of the root module.
144+ use axum_htmx :: serde :: HxResponseTrigger ;
145+
146+ async fn index () -> (& 'static str , HxResponseTrigger ) {
147+ let event = HxEvent :: new_with_data (
148+ " my-event" ,
149+ json! ({" level" : " info" , " message" : {
150+ " title" : " Hello, world!" ,
151+ " body" : " This is a test message." ,
152+ }}),
153+ )
154+ . unwrap ();
155+
156+ (" Hello, world!" , HxResponseTrigger (event ))
157+ }
158+ ```
159+
160+ ``` rust
161+ ```
162+
133163### Example: Router Guard
134164
135165``` rust
You can’t perform that action at this time.
0 commit comments