-
-
Notifications
You must be signed in to change notification settings - Fork 273
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
scripts: Adding Attributes to Script Tags Generated from Script Templates #601
Comments
@a-h Would it be reasonable/worth it to add some configuration/rendering options to the |
As a workaround, https://templ.guide/syntax-and-usage/using-with-go-templates#using-htmltemplate-in-a-templ-component It'd be more convenient to be able to pass attributes, such as |
This sounds like a very valid use-case. Are there any design suggestions? As a complete alternative, it could be possible to add a script graph(data []TimeValue) {
const chart = LightweightCharts.createChart(document.body, { width: 400, height: 300 });
const lineSeries = chart.addLineSeries();
lineSeries.setData(data);
}
templ page(data []TimeValue) {
<html>
<head>
<script src="https://unpkg.com/lightweight-charts/dist/lightweight-charts.standalone.production.js"></script>
</head>
<body onload={ graph(data) }></body>
</html>
}
func main() {
nonce := generateNonce()
ctx := templ.ContextWithNonce(nonce)
page(getData()).Render(ctx, os.Stout)
} |
I've put together an example of using |
Also templ scripts can now be given a nonce so I think we can close this. |
Background
My script tags require a
nonce
attributed because a Content Security Policy is enforced. As an example:However, for some scripts I need to pass in go data. I can do that as mentioned in the docs:
Issue
Because of the Content Security Policy, scripts generated from the script template will never run because they don't have the
nonce
attribute with the correct value.Request
Can there be some way to configure script attributes in the script template?
The text was updated successfully, but these errors were encountered: