Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6092371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:26:05+00:00 2026-05-23T12:26:05+00:00

I’m having a hard time dealing with stylesheets and javascripts. All the examples for

  • 0

I’m having a hard time dealing with stylesheets and javascripts.

All the examples for assetic + twig assume that you know beforehand all the paths of the files you will need.

Suppose I want to create an ‘About’ page.

The ‘about.html.twig’ template extends from ‘layout.html.twig’.

The layout must have a couple of .css and .js that will be used throughout the entire site.

The about template must load other .css and .js files that are specific to it.

So the stylesheets block looks something like this:

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

Then how do I use assetic in this case?

Am I supposed to send all the assets of the site from the beginning, because even then, the performance will be boosted?

The problem is that there may be conflicts between the .css, sometimes you load a .css just to override your own base settings, so you can’t just create a single .css for the whole site.

I also tried setting an array to store all the paths, then loop, and pass the paths to assetic. But it seems like the syntax css[] = ‘another_path.css’ is not supported by twig. You have to set the entire array in one assignment

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:26:05+00:00Added an answer on May 23, 2026 at 12:26 pm

    Yes you are correct the syntax for the assetic Twig extensions does expect you do know all the assets you want to include. But that is by design because for production it is intended that you dump out the combined and minified CSS/JS so that it can handled by the web server without getting PHP involved.

    My best suggestion for you is to identify all your stylesheets that you are happy to include on all pages of your site and make an assetic stylesheet call for them.

    Then for specific pages where you need additional stylesheets you could make a second assetic call where required.

    layout.html.twig

    // do 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 an empty block for extra 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, which is possibly easier, is to just refactor your CSS so you can have all the styles downloaded in one go.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.