我正在尝试使用document.write
javascript函数在我的模板中设置外部css
文件,但是,我想通过Twig
执行此操作,就像这样:
document.write('<link href="{{ asset('bundles/activos/css/app-orange.css') }}" rel="stylesheet" >');
但它不起作用。为什么这个document.write
函数不起作用?我可以将Twig
代码放在那里吗?
或者将css
路由Twig
传递给document.write
javascript函数的最佳方法是什么?
对不起,如果我的英语不好。我希望你明白。感谢。
答案 0 :(得分:1)
试试这个
{% 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 %}
答案 1 :(得分:1)
最后我意识到了答案。问题是我在document.write()
函数中使用了$(document).ready()
函数。我的错误不是在这里发布整个代码,所以你可以看到。直到现在我才知道我无法在document.write()
函数中使用$(document).ready()
函数。无论如何,我要感谢大家的意见和答案!