Replies: 2 comments
-
HI @KulvSingh, attributes that expect a script must be either a constant string:
Or must be a
This is because templ is trying to prevent you from accidentally introducing an XSS. If you have a Go string expression, it may have come from an untrusted source (i.e. user input). templ's script templates (example 2 above) manage the JSON escaping of Go values and pass them to a JavaScript function. Alternatively, example 1 shows a constant string attribute, which can only have been written by the developer, and therefore is assumed to be "safe". Perhaps the documentation needs to make this clearer. |
Beta Was this translation helpful? Give feedback.
-
Hi, this is getting compiled now after the solution of having the script function thought event hx-on::after-swap does not seem to get fired. Thanks. |
Beta Was this translation helpful? Give feedback.
-
hx-on::after-swap={ fmt.Sprintf("htmx.find('#D001').focus()") }
This htmx attribute having "::" with value being an expression is evaluating to be an error as following
cannot use fmt.Sprintf("htmx.find('#D001').focus()") (value of type string) as templ.ComponentScript value in variable declarationcompilerIncompatibleAssign
Beta Was this translation helpful? Give feedback.
All reactions