Brent
Brent

Reputation: 2485

Symfony2 Twig Style Sheet

I am following a tutorial for symphony 2 but cant get the style sheet to load all I get is a 404.

I have tried also adding it into the route but I get a permission error on the style sheet.

app/Resources/views/base.html.twig

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html"; charset=utf-8" />
        <title>{% block title %}symblog{% endblock %} - symblog</title>
        {% block stylesheets %}

            <link href="{{ asset('css/screen.css') }}" type="text/css" rel="stylesheet" />
        {% endblock %}

I have added the style sheet into app/Resources/views/web/css/screen.css

Any ideas why this is not working? Tutorial

Upvotes: 0

Views: 146

Answers (2)

Johannes Reiners
Johannes Reiners

Reputation: 678

Projects assets (resources from your app/ folder) are ignored by assets:install command. Only resources from bundles will be copied into the web/ folder automatically.

You should place your app (project) resources directly in the web/ folder.

http://symfony.com/doc/current/cookbook/assetic/asset_management.html

By the way: ONLY the web/ folder is public. Look at the rendered source code of your html in the browser and you will see that your css file is prefixed with a web/. This is what the asset() command does

Upvotes: 1

ozahorulia
ozahorulia

Reputation: 10084

You put css files in a wrong directory.

It should be web/css/screen.css instead of app/Resources/views/web/css/screen.css

I also suggest you to use assetic instead of manually put css and js to the web directory. These articles might help (take a look at the assets:install command):

Upvotes: 2

Related Questions