0

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.

6
  • Where did you put the particular line of code? Inside a twig template or in an external js file? Commented Aug 8, 2016 at 14:20
  • Inside a twig template Commented Aug 8, 2016 at 14:20
  • Then it should work, are you getting any errors? Check javascript console? Commented Aug 8, 2016 at 14:38
  • the page and also the console stays blank Commented Aug 8, 2016 at 14:53
  • 2
    Ok, I have post it in another question because the real problem is bigger and maybe there is anothe way to solve it whithout using the document.ready function. This is the link. @DarkBee Commented Aug 8, 2016 at 15:24

2 Answers 2

1

Try this

{% stylesheets
    "@ActivosBundle/Resources/public/css/app-orange.css"
    "%kerner.root_dir%/Resources/css/main.css"
%}
<link type="text/css" rel="stylesheet" media="all" href="{{ asset_url }}" />
{% endstylesheets %}
Sign up to request clarification or add additional context in comments.

2 Comments

I need it inside the document.write js function because I do more things with that in the js function
I have post it in another question because the real problem is bigger and maybe there is anothe way to solve it whithout using the document.ready function. If you want, check this link. Thanks for your help. @YamenImadNassif
1

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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.