I'm using Symfony2, with Assetic and Twig. I have various frontend libraries - Backbone, jQuery, jQuery UI, and Bootstrap. Both Bootstrap and jQuery UI include CSS and JS files.
Is there a way that I can define the resources they need to include (including dependencies), and then in Twig / Assetic just include all those resources in one tag? What I'd look to have is something like:
// config.yml <!-- DOES NOT WORK -->
assetic:
resources:
jquery:
js: /filepath/to/jquery.js
jquery_ui:
dependencies: jquery
css: /filepath/to/jqueryui.css
js: /filepath/to/jqueryui.js
less:
js: /filepath/to/less.js
bootstrap:
dependencies: { less, jquery }
js: /filepath/to/bootstrap.js
css: /filepath/to/bootstrap.css
backbone:
dependencies: { jquery }
js: { /filepath/to/underscore.js, /filepath/to/backbone.js }
// view.html.twig
{% use jquery_ui %}
{% use bootstrap %}
// outputs all js and css for jQuery, jQueryUI, Less, Backbone, and Bootstrap
I found a couple of related questions:
- How to define Assetic resources in Symfony 2 yml or xml configuration file?
- Symfony2 Assetic + Twig Template JavaScript Inheritance
but neither seems to involve defining the resources in config.yml. Instead, they define them in base.html.twig
but that's what I'm trying to avoid.
I tried using the use
tag in Twig, by defining a template called 'jquery_ui' and using {% stylesheets %}
and {% javascripts %}
in that block and then in base.html.twig
putting {% use "jquery-ui.html" %}
. However, use
won't import the template because it has a body.
package.json
in the root of the project, and a keep notes of how to rebuild the workspace in files at the root of the project. Sometimes I also add scripts in theapp/
directory. – Jeroldjeroma