php - How to dynamically save all the .css paths and then pass them to assetic for compression? (in Symfony 2) -


i'm having hard time dealing stylesheets , javascripts.

all examples assetic + twig assume know beforehand paths of files need.

suppose want create 'about' page.

the 'about.html.twig' template extends 'layout.html.twig'.

the layout must have couple of .css , .js used throughout entire site.

the template must load other .css , .js files specific it.

so stylesheets block looks this:

{% block stylesheets %} {{ parent() }} <link href='bla'> {# more stylesheets #} {% endblock %} 

then how use assetic in case?

am supposed send assets of site beginning, because then, performance boosted?

the problem there may conflicts between .css, load .css override own base settings, can't create single .css whole site.

i tried setting array store paths, loop, , pass paths assetic. seems syntax css[] = 'another_path.css' not supported twig. have set entire array in 1 assignment

yes correct syntax assetic twig extensions expect know assets want include. design because production intended dump out combined , minified css/js can handled web server without getting php involved.

my best suggestion identify stylesheets happy include on pages of site , make assetic stylesheet call them.

then specific pages need additional stylesheets make second assetic call required.

layout.html.twig

// common styles {% stylesheets 'css/reset.css'                'css/960.css'                'css/foobar.css'                filter='yui_css' %}     <link rel="stylesheet" media="screen" href="{{ asset_url }}" /> {% endstylesheets %}  // use empty block styles {% block extra_styles %}{% endblock %}  

someview.html.twig

{% block extra_styles %}     {% stylesheets 'css/about1.css'                    'css/about2.css'                    filter='yui_css' %}         <link rel="stylesheet" media="screen" href="{{ asset_url }}" />     {% endstylesheets %} {% endblock %} 

another solution, possibly easier, refactor css can have styles downloaded in 1 go.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -