Search code examples
phpcsssymfonyassets

stylesheet not found with asset in symfony


I am currently learning symfony (v. 4) and trying to include a .css file in a template. However, I get this mistake: GET http://localhost:8000/css/app.css net:: ERR_ABORTED

My template (src/templates/index/tracking.html.twig):

{% extends' base.html.twig' %}

{% block stylesheets %}
    <link rel= "stylesheet" href="{{ asset ('css/app.css') }}" />
{% end block %}
...

My controller (src/Controller/TrackingController.php):

<?php
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use App\Entity\Time;

class TrackingController extends Controller {
    public function index () {
        return $this->render ('index/tracking.html.twig');
    }
}

My CSS file is located under assets/css/app.css. What am I doing wrong? How can I integrate the CSS file correctly?


Solution

  • If you don't use Webpack-Encore, your css file should be in the "public/css" folder.