diff --git a/README.md b/README.md index 43338f6..9d0da4b 100644 --- a/README.md +++ b/README.md @@ -224,6 +224,18 @@ content := elem.Div(nil, In this example, the Fragment function is used to insert the nodes into the parent div without introducing any additional wrapper elements. This keeps the HTML output clean and simple. +### Handling JSON Strings and Special Characters in Attributes + +When using attributes that require JSON strings or special characters (like quotes), make sure to wrap these strings in single quotes. This prevents the library from adding extra quotes around your value. For example: + +```go +content := elem.Div(attrs.Props{ + attrs.ID: "my-div", + attrs.Class: "special 'class'", + attrs.Data: `'{"key": "value"}'`, +}, elem.Text("Content")) +``` + ## Advanced CSS Styling with `StyleManager` For projects requiring advanced CSS styling capabilities, including support for animations, pseudo-classes, and responsive design via media queries, the `stylemanager` subpackage offers a powerful solution. Integrated seamlessly with `elem-go`, it allows developers to programmatically create and manage complex CSS styles within the type-safe environment of Go. diff --git a/htmx/README.md b/htmx/README.md index 0d54e60..e1dbaf0 100644 --- a/htmx/README.md +++ b/htmx/README.md @@ -115,4 +115,15 @@ contentDiv := elem.Div(attrs.Props{attrs.ID: "result-div"}, elem.Text("Initial c pageContent := elem.Div(nil, button, contentDiv) ``` -When the button is clicked, `htmx` will fetch content from the `/fetch-content` endpoint and replace the content inside the `#result-div`. \ No newline at end of file +When the button is clicked, `htmx` will fetch content from the `/fetch-content` endpoint and replace the content inside the `#result-div`. + +## Handling JSON Strings in Attributes + +When using attributes like `hx-vals` that require JSON strings, ensure the JSON is wrapped in single quotes. This is necessary for correct rendering by `htmx`. For example: + +```go +content := elem.Div(attrs.Props{ + htmx.HXGet: "/example", + htmx.HXVals: `'{"myVal": "My Value"}'`, +}, elem.Text("Get Some HTML, Including A Value in the Request")) +``` \ No newline at end of file