3

I followed this tutorial to add sass support in symfony:

https://alexandre.salome.fr/blog/sass-compass-assetic-in-ten-minutes

So far, I have a stylesheets.html.twig with this content:

{% stylesheets filter="sass"
    "css/main.scss"
    "css/details.scss"
    "css/talk.scss"
%}
    <link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}

that works fine, but how do I add more stylesheets when a specific *.html.twig is used? I guess I cant use blocks when using the filter function like this above.

2 Answers 2

2

For Synfony2 it should look like:

{% block css %}
    {% stylesheets output='css/compiled/index.css'
        '@MainBundle/Resources/css/editable.css'
    %}
    <link rel="stylesheet" href="{{ asset_url }}" />
    {% endstylesheets %}
{% endblock %}
Sign up to request clarification or add additional context in comments.

Comments

1

ok dimitrio, your answer directed me to the solution

first problem was, that the stylesheets.html.twig was included, and therefor I couldnt access and overide the block inside it, so I replaced it by use:

#base.html.twig
{% use "::stylesheets.html.twig" %}           
{% block stylesheets %}
    {{ parent() }}
{% endblock %}

and inside the stylesheets.html.twig

#stylehseets.html.twig
{% block stylesheets %}

    {% stylesheets filter="sass"
        "css/main.scss"
        "css/basic.scss"
    %}
        <link rel="stylesheet" href="{{ asset_url }}" />
    {% endstylesheets %}

{% endblock %}

Inside my specific twig I had to add content to the block

{% block stylesheets %}

    {{ parent() }}

    {% stylesheets filter="sass"
        "css/specific/show.scss"
    %}
        <link rel="stylesheet" href="{{ asset_url }}" />
    {% endstylesheets %}
{% endblock %}

It works nice, but isn't there a solution that is shorter for the specific twig? Iam looking for something like

{% addstylesheet 'css/specific/show.scss' %}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.