troopers / assetic-injector-bundle
This bundle allow you to define global javascripts and stylesheets
Installs: 24 757
Dependents: 1
Suggesters: 1
Security: 0
Stars: 20
Watchers: 7
Forks: 10
Open Issues: 2
Type:symfony-bundle
Requires
- php: >=5.3.2
- symfony/assetic-bundle: ~2.7
- twig/twig: ~2.0
This package is not auto-updated.
Last update: 2021-12-21 22:33:21 UTC
README
=============
AsseticInjectorBundle
Description
The AsseticInjectorBundle allows you to automatically include javascripts and stylesheets anywhere in your project.
This bundle will scan every registered bundles and search for an assetic_injector.json file. From this file, the injector will collect the resources and inject them into the assetic engine. To include them, you have to define a tag (foot, head, custom, ... actually the one you choose) and add the tag in the wanted assetic block.
Install
With Composer :
Add this line in your composer.json file :
"troopers/assetic-injector-bundle": "~1.0"
Declare the bundle in your AppKernel.php:
public function registerBundles() {
$bundles = array(
[...]
new Troopers\AsseticInjectorBundle\TroopersAsseticInjectorBundle(),
[...]
How it works
.. Declare an assetic_injector.json in the Resource/config folder of your application or bundle.
Within this file, list all the tags and the correspondant resource to inject :
{
"require_all":
{
"javascripts":
{
"head": "@MyBundle/Resources/public/js/myscript.js"
},
"stylesheets":
{
"head": "@MyBundle/Resources/public/css/mystyle.css"
}
}
}
.. Include the correspondant tag in your assetic's block with the code : injector="tag"
i.e :
{% javascripts injector="head"
'@MyAcmeDemoBundle/Resources/public/jsloremipsumdolorsitamet.js'
%}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
.. Results
The resource associated to the tag is injected with assetic_injector.json.
i.e :
{% javascripts injector="head"
'@MyAcmeDemoBundle/Resources/public/jsloremipsumdolorsitamet.js'
'@MyBundle/Resources/public/js/myscript.js'
%}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
Enjoy !
No more needs to include javascript or stylesheets from assetic injector's ready bundles ! Just add the tag and here you are !