eZ Community » Forums » Setup & design » ez 5.4 - define css files by siteaccess
expandshrink

ez 5.4 - define css files by siteaccess

ez 5.4 - define css files by siteaccess

Tuesday 20 January 2015 12:25:43 pm - 6 replies

Hi ,  I have one instance of ezpublish with a lot of siteaccess on it.

I would like to define which css files are loaded per siteaccess 

how can I do that ?

thx,

Fabien 

Tuesday 20 January 2015 6:05:28 pm

Hello Fabien,

If your using legacy templates you can easily do what your asking about!

In fact eZ Publish / eZ Webin does this by default and has done so for quite some time.

You will want to learn from a default eZ Publish & eZ Webin installation (sorry can't link to installed settings files in this case for examples).

Do a test installation and review the settings in: settings/siteaccess/ezwebin_site_user/design.ini.append.php

You will find that there is a settings block (array) called: 

[StylesheetSettings]
FrontendCSSFileList[]
FrontendCSSFileList[]=custom-siteaccess-css-file.css

This is used in the default ezwebin page head templates to load css files.

https://github.com/ezsystems/ezwe...bin/templates/page_head_style.tpl#L6

Remember to use FrontendCSSFileList and not CSSFileList (as this is deprecated).

And again these design.ini settings can be set per siteaccess which provides for the feature your asking about.

I hope this helps! 

Cheers,
Heath

Modified on Tuesday 20 January 2015 6:06:32 pm by // Heath

Wednesday 21 January 2015 9:23:31 am

Hi Fabien,

in eZ5, the quick and (not that) dirty way is to use the global twig variable ezpublish.siteaccess to include the right assets. Alternatively, you could define a service to provide the right asset lists according to current siteaccess and define it as a global Twig helper.

 

Hope this helps.

 

Ben

Wednesday 21 January 2015 2:21:43 pm

Hi, 

@Heath : no legacy for me happy.gif Emoticon

@Benjamin : if you use the global twig variable, I don't think you can use in in a {% stylesheet...%} block, as the links to the assets has to be a constant

I will think about it a little more 

thanks,

Fabien  

Wednesday 21 January 2015 2:31:37 pm

Well, what I thought of was something like this (probably non working code):

{% if ezpublish.siteaccess.name == 'first' %}

<link href="{{asset('bundles/site/css/first.css')}}" />

{% else if ezpublish.siteaccess.name == 'second' %}

<link href="{{asset('bundles/site/css/second.css')}}" />

{% endif %}

Hence the "quick and dirty" remark.

Wednesday 21 January 2015 2:44:19 pm

ah ok blunk.gif Emoticon

I have developped an override system for the page_head by siteacess.

So i will put my css files list into each one, but as it was directly possible in the ez 4.x version, i was wondering if it was possible with ez5.

I have more than 45 siteaccess, so the "if" thing would be .. terrible ... happy.gif Emoticon

thanks for your help

Wednesday 21 January 2015 2:53:58 pm

If you're using 5.4, you can list your CSS files in semantic configuration, inject it in a service and return it as a global variable in a twig extension

https://doc.ez.no/display/EZP/How+to+expose+SiteAccess+aware+configuration+for+your+bundle

http://symfony.com/doc/current/reference/dic_tags.html#reference-dic-tags-twig-extension

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from