1

I have one base .css file under app/Resources/public/css/. Every file should include it so I wanna place it in the layout file. I also want to include additional css files if there'd be any. This is how my layout looks like:

<!DOCTYPE>
<html>
    <head>
        <meta charset="UTF-8">
        <title>{% block title %}Title{% endblock %}</title>
        <link rel="stylesheet" type="text/css" charset="UTF-8" media="all" href="{{ asset('css/base.css') }}">
        {% block stylesheets %}{% endblock %}
    </head>
    <body>
        {% block body %}{% endblock %}
        {% block javascripts %}{% endblock %}
    </body>
</html>

As far as I know it should include my base .css file and any other .css files I use in stylesheet block.

However it doesn't work. It generates the relative url to the css file, but it just doesn't open. Typing this url to the browser (localhost/project/web/css/base.css) gives some uncaught exception.

Fatal error: Uncaught exception 'Symfony\Component\Routing\Exception\ResourceNotFoundException' in C:\xampp\htdocs\MyFitnessManager\app\cache\prod\appProdUrlMatcher.php:33 Stack trace: #0 C:\xampp\htdocs\MyFitnessManager\app\cache\prod\classes.php(1207): appProdUrlMatcher->match('/css/base.css') #1 C:\xampp\htdocs\MyFitnessManager\app\cache\prod\classes.php(1872): Symfony\Component\Routing\Router->match('/css/base.css') #2 [internal function]: Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest(Object(Symfony\Component\HttpKernel\Event\GetResponseEvent)) #3 C:\xampp\htdocs\MyFitnessManager\app\cache\prod\classes.php(1667): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\GetResponseEvent)) #4 C:\xampp\htdocs\MyFitnessManager\app\cache\prod\classes.php(1600): Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(Array, 'kernel.request', Object(Symfony\Component\HttpKernel\Event\GetResponseEvent)) #5 C:\xampp\htdocs\MyFitnessManager\app\cache\prod\classes.php(1764): Symfony\Comp in C:\xampp\htdocs\MyFitnessManager\app\cache\prod\classes.php on line 1883

What's going on?

1 Answer 1

2

If your primary layout that you're extending is in app/Resources/views you can use something like this:

{% stylesheets
    '../app/Resources/public/css/base.css' %}
    <link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
Sign up to request clarification or add additional context in comments.

7 Comments

I tried that but it shows An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "_assetic_17022fb_0" as such route does not exist.") in "CoreBundle:Default:index.html.twig"
Post the view code for CoreBundle:Default:index.html.twig or is that the view above in your post?
{% extends "::base.html.twig" %} {% block body %} Hello world! {% endblock %}
That's it. It works perfectly when I delete the whole stylesheets tag.
Ok, based on what you said everything should be working. This is the exact structure I use in most of my apps. Try doing a manual cache clear eg rm -rf app/cache/*
|

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.