bigskysoftware / htmx

</> htmx - high power tools for HTML
https://htmx.org
Other
37.99k stars 1.29k forks source link

Tutorial for using HX-Request header #366

Open benpate opened 3 years ago

benpate commented 3 years ago

As mentioned on Discord, it would be helpful to have a tutorial that shows how to use the HX-Request header to modify returns from the server, showing a full page if this value is not present, and only returning a partial page if it is.

aburd commented 7 months ago

I’m not sure about tutorial, but the book mentions something similar to this:

Htmx takes advantage of this feature of HTTP and adds additional headers and, therefore, additional context to the HTTP requests that it makes. This allows you to inspect those headers and choose what logic to execute on the server, and what sort of HTML response you want to send to the client.

Here is a table of the HTTP headers that htmx includes in HTTP requests: … Let’s add some conditional logic to our controller to look for that header and, if the value is search, we render only the rows rather than the whole index.html template:

https://hypermedia.systems/more-htmx-patterns/