I want to include (yes include) some js file into a big js with Twig but from another directory.
I explain. This is my organisation :
AcmeBundle/
Script/
blabla1.js
blabla2.js
Resources/
views/
script.js.twig
I want to do two include of blabla1 and blabla2 in the script.js.twig. Something like that :
{% include '@AcmeBundle/Script/blabla1.js' %}
{% include '@AcmeBundle/Script/blabla2.js' %}
But I don't arrive... And I don't want to put blablas script into Resources.
Is it possible ?
Thanks in advance,
Smooba
Yup.
You can just add them in your Assetic javascripts call like usual (or not usual if you are not using it at the moment).
{% javascripts
'@AcmeBundle/Scripts/blabla1.js'
'@AcmeBundle/Scripts/blabla2.js'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
You first move/copy your js fiels to assets folder you can do by this command
php app/console assets:install
then into your twig file you can include that js like this
<script type="text/javascript" src="{{ asset('bundles/AcmeBundle/Script/blabla1.js')}}" ></script>
<script type="text/javascript" src="{{ asset('bundles/AcmeBundle/Script/blabla2.js')}}" ></script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.