Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining Assetic Resources across inherited templates

We are building a new site using Symfony2, and Assetic looks very promising for resource management, in particular for combining and processing all js/css files together automatically.

We wil have some resources that are used site wide, and some that are specific to particular pages. We will also be using a three tiered inherited approach to templates.

Is there a way to combine the two concepts, i.e. to automatically add additional resources in inherited templates so that they are all output as a single resource?

like image 712
Ken Cooper Avatar asked Aug 05 '11 15:08

Ken Cooper


1 Answers

You can actually do the following:

In layout.html.twig (or whatever your layout is)

{% block stylesheets %}     {% stylesheets 'your_assets_here' %}          <link rel="stylesheet" href="{{ asset_url }}" />     {% endstylesheets %} {% endblock %} 

And in any template that extends that layout:

{% block stylesheets %}     {{ parent() }}     {% stylesheets 'additional_assets_here' %}          <link rel="stylesheet" href="{{ asset_url }}" />     {% endstylesheets %} {% endblock %} 

Then you wouldn't need to retype all the old assets as suggested by Nemanja Niljkovic

like image 185
Populus Avatar answered Sep 28 '22 21:09

Populus