You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In short, if your websocket connection works, but you don't see anything displayed, then make sure that the html you are receiving from the websocket has the correct id attribute value, that matches the id of the element that it should replace.
Example 4: Using client-side-templates with ws extension
Here is an example of using the client-side-templates extension (and a mustache template), to transform json object messages received from the ws extension to html that satisfies the ws swapping mechanism. It also demonstrate the use of the debug extension to get more information about the execution steps of htmx.
This is like Example 2, but without json reshaping.
There are a few examples that could be added that would help users to better understand how to work with the websocket extension.
Example 1: Explicit Websocket message example
This StackOverflow issue explains the situation: https://stackoverflow.com/questions/77422127/htmx-websockets-are-not-replacing-content-in-dom
In short, if your websocket connection works, but you don't see anything displayed, then make sure that the html you are receiving from the websocket has the correct
id
attribute value, that matches theid
of the element that it should replace.Given the usage example taken from the docs:
The documentation can be improved by explicitly stating what an example message from the websocket should look like for the given example:
The documentation page (https://htmx.org/extensions/web-sockets/#receiving-messages-from-a-websocket) does mention it, but for newcomers it is not so clear exactly what is meant by it:
Example 2: Reshaping json using a custom extension
An example can be added to show how to transform incoming json data to another shape using a custom
htmx
extension.With inspiration taken from: https://github.com/wodny/htmx-experiments/blob/master/websockets-and-client-side-templates/js/main.js
Example 3: Transforming json to html using a custom extension
An example can be added to show how to transform incoming json data to html using a custom
htmx
extension.With inspiration taken from: https://github.com/wodny/htmx-experiments/blob/master/websockets-and-client-side-templates/js/main.js
Example 4: Using client-side-templates with ws extension
Here is an example of using the
client-side-templates
extension (and amustache
template), to transform json object messages received from thews
extension to html that satisfies thews
swapping mechanism. It also demonstrate the use of thedebug
extension to get more information about the execution steps ofhtmx
.This is like Example 2, but without json reshaping.
With inspiration taken from:
The text was updated successfully, but these errors were encountered: