<p>You can use the <a href="https://craftcms.com/docs/4.x/dev/tags.html#script" rel="nofollow noreferrer"><code>{% script %}</code></a> tag instead:</p>
<pre><code>{% script with { nonce } %}
    code here
{% endscript %}
</code></pre>

CC BY-SA 4.0
2024-03-05T19:17:00.033Z
That works! Thanks so much. And yes, as you pointed out, 'with { nonce }' is all that's needed to render the variable in the tag.
Jason McKinney
CC BY-SA 4.0
2024-03-05T18:52:51.197Z
2024-03-05T18:52:51.197Z
Mats Mikkel Rummelhoff
<p>While it's possible to pass an html element into a JS file declaration using 'with' as in:</p>
<pre><code>{% js '/url/here' with { nonce: { nonce } } %}
</code></pre>
<p>this approach is not available for a JS inline code block for some reason:</p>
<pre><code>{% js with { nonce: { nonce } } %} 
  code here 
{% endjs %} //doesn't work
</code></pre>
<p>Has anyone found a workaround for this?</p>

<tags><js>
Adding a nonce tag to an inline code block
# Adding a nonce tag to an inline code block

(Asked by: username_0 on 2024-03-05)

While it's possible to pass an html element into a JS file declaration using 'with' as in:
{% js '/url/here' with { nonce: { nonce } } %}

this approach is not available for a JS inline code block for some reason:
{% js with { nonce: { nonce } } %} 
  code here 
{% endjs %} //doesn't work

Has anyone found a workaround for this?

**Tags:** tags, js

---

## 1 answers

### Answer by username_1 on 2024-03-05. Score: 1 | Accepted answer

You can use the {% script %} tag instead:
{% script with { nonce } %}
    code here
{% endscript %}

> **Comments:**
> **username_0**: That works! Thanks so much. And yes, as you pointed out, 'with { nonce }' is all that's needed to render the variable in the tag.  

---

