-
-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: add templ.JSONScript and templ.JSON functions #739
Comments
As per #601, the |
This makes a lot of sense to me, I think external JS/TS files is the way to go for DX, we can't match and keep up with that experience in templ scripts without a ton of complexity. I like that it's a step towards the rendered HTML being more similar to the originally written template too. Additional functions proposed make sense too, we've seen enough people asking how to do this that a runtime function seems fitting. |
This sounds great to me. I am exploring incremental adoption of templ SSR in a react project with a go api. |
Added PR in #745 |
The page at https://templ.guide/syntax-and-usage/script-templates currently mentions the use of the
templ script
script template as the main way to pass Go data to scripts, and demonstrates the use ofonclick
attributes, which are listed as not best practice in MDN.In the draft PR at https://github.com/a-h/templ/pull/738/files I demonstrate how to use data attributes and script elements to pass data, and following the best practice described in MDN docs.
However, I needed to create:
templ.JSON
function)<script>
element containing JSON data (the proposedtempl.JSONScript
function).I propose:
templ script
, on the basis that the developer experience of writing JS/TS inside a TS file is better, and can more easily include intellisense etc.Thoughts?
The text was updated successfully, but these errors were encountered: