approach is quite bad IMHO
Instead of just "baking in" my values into the JavaScript source, I now have to bake them into a separate <script id="myValues" type="application/json"> tag, and then get the DOM element and parse the JSON:
templ myTemplate(foo bool, bar string) {
@templ.JSONScript("myTemplate_fooBar", struct {
Foo bool
Bar string
}{Foo: foo, Bar: bar})
<script type="text/javascript">
const params = JSON.parse(
document.getElementById('myTemplate_fooBar').textContent
)
console.log(params.Foo, params.Bar)
</script>
}
This is worse because we now have to parse JSON (cheap, but not free) and pollute the DOM with unnecessary ids and tags
If I had to guess, something something security
Обсуждают сегодня