in a twig template I want to insert javascript text like this :
<script type="text/javascript">
{{ "var applicationBundleName = '" ~ application_bundle_name ~ "';" | raw}}
</script>
When the html is rendered, I have this :
<script type="text/javascript">
var applicationBundleName = 'MyBundle_name';
</script>
While rendering the quotes are replaces by their html entities => javascript error
How can I say not to remplace special characters by their codes ? or maybe there is a nicer way to do that..
Thank you
You have to quote only the twig variable:
<script type="text/javascript">
var applicationBundleName = "{{ application_bundle_name|raw }}";
</script>
I'm not sure but I think that if the variable is a string you don't need to use de raw
filter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With