eZ Platform Discussions

[Assetic] Add css file for siteaccess

version2

#1

Bonjour,

In a multi-site context, I’m looking for a technique to have a css file specific to the current siteaccess.

All my sites have exactly the same code (exception: the style sheet to make the “swap color”)

I tried that:

        {% block stylesheets %}
            {% set site_css_file_name = 'bundles/app/css/site/'~ezpublish.siteaccess.name~'.css'  %}
            {{ dump(site_css_file_name) }} {# "bundles/app/css/site/site_1.css" #}
            {% stylesheets
                'bundles/app/css/*'
                site_css_file_name
                filter='cssrewrite' %}
                <link rel="stylesheet" href="{{ asset_url }}" />
            {% endstylesheets %}
        {% endblock %}

UndefinedMethodException
HTTP 500 Internal Server Error
Attempted to call an undefined method named “getFilename” of class “Twig_TokenStream”.

But it’s not working.
And besides, it’s not beautiful.

How would you solve this problem?


#2

Hi,
as I had more siteaccess-specific requirement , I solved it with ez_core_extra bundle.

I simply wrote this in config.yml or ezplatform.yml

ez_core_extra:
    system:
        my_siteaccess:
            twig_globals:
                css_file: my-siteaccess.css

and then simply use it like this <link rel="stylesheet" type="text/css" href="{{ asset('bundles/app/css/' ~ css_file ) }}">


#3

The @amirkoklan solution is interesting. But she has the same problem if we try to use assetic.

After that it doesn’t matter if I have two css files instead of one… ?


#4

Hi,
ez design engine could solve your problem:
https://doc.ezplatform.com/en/2.2/guide/design_engine/#design-usage-with-assets