Adriana Hernández Adriana Hernández - 4 months ago 16
Twig Question

document.write javascript function is not working

I'm trying to use the

document.write
javascript function to set an external
css
file in my template, but, I want to do this via
Twig
just like this:

document.write('<link href="{{ asset('bundles/activos/css/app-orange.css') }}" rel="stylesheet" >');


But it does not work. Why this
document.write
function is not working? Can I put that
Twig
code in there?

Or what is the best way to pass a
css
route with
Twig
to a
document.write
javascript function?

Sorry if my english is not good. I hope you understand. Thanks.

Answer

Finally I realize the answer. The problem is that I was using the document.write() function inside of $(document).ready() function. My mistake was not to post the entire code here so you could see. I didn't know until now that I could not use document.write() function inside of the $(document).ready() function. Anyway, I want to thank you all for the comments and answers!