symfony2 - Twig Assetic Stylesheets Among Several Templates -
symfony2 - Twig Assetic Stylesheets Among Several Templates -
i'm trying add together stylesheets array twig templates extend through sec , 3rd levels aggregated styles carry through.
this topic related combining assetic resources across inherited templates
from config.yml, made global array mystyles
can add together list of necessary styles "bubble up" through rendering process.
twig: debug: %kernel.debug% strict_variables: %kernel.debug% globals: mystyles: []
the first template called action communicatorbundle/resources/views/admin/workspace.html.twig , i've set specific style page called admin.workspace.css
.
{% extends "djcommunicatorbundle::base.html.twig" %} {% set mystyles = ["@djcommunicatorbundle/resources/public/css/admin.workspace.css"]|merge(mystyles) %}
it extends communicatorbundle/resources/views/base.html.twig has it's own requirement data-table.css
.
{% extends "djsharedbundle::base.html.twig" %} {% set mystyles = ["@djcommunicatorbundle/resources/public/css/data-table.css" ]|merge(mystyles) %}
finally, load outermost template, sharedbundle/resources/views/base.html.twig, has it's own styles add together before others.
<head> {% set mystyles = ['@djsharedbundle/resources/public/css/global.css', '@djsharedbundle/resources/public/css/grid.990.9-col.css']|merge(mystyles) %} {% stylesheets {{ mystyles }} %} <link rel="stylesheet" href="{{ asset_url }}" type="text/css" /> {% endstylesheets %} </head>
however, breaks @ line
{% stylesheets {{ mystyles }} %}
inspite of type of test prints array expect in proper order
{{ mystyles|join(', ') }}
it seems {% stylesheets %}
tag wants next snippit work (which understandably not array object, whitespace separated list of delimited strings).
{% stylesheets '@djsharedbundle/resources/public/css/global.css' '@djsharedbundle/resources/public/css/grid.990.9-col.css' '@djcommunicatorbundle/resources/public/css/data-table.css' '@djcommunicatorbundle/resources/public/css/admin.workspace.css' %} <link rel="stylesheet" href="{{ asset_url }}" type="text/css" /> {% endstylesheets %}
even then, tried setting string such long value , printing it, doesn't work either:
{% set str = "@djsharedbundle/resources/public/css/global.css @djsharedbundle/resources/public/css/grid.990.9-col.css @djcommunicatorbundle/resources/public/css/data-table.css @djcommunicatorbundle/resources/public/css/admin.workspace.css" %} {% stylesheets {{ str }} %}
i sense global should viable solution, though not working. i'm close. might prepare this?
this not possible right because assetic statically analyzes templates find assets you've defined there. supporting these dynamic cases on roadmap.
symfony2 twig
Comments
Post a Comment