Search code examples
phpcsssymfonytwigsymfony4

Symfony 4 - Template issue css displayed


I just uploaded my website on ovh and a problem occured when all was right on localhost. Indeed, my templates were all displayed as I wanted. Now that the website is on the server, the half of the webpages are not displaying the templates but their own CSS code !

Here are my MainController and the Template on a page that displays right :

/**
* @Route("/", name="home")
*/
public function home()
{
    $home = $this->getDoctrine()
        ->getRepository(Homepage::class)
        ->find(1);
    return $this->render('main/home.html.twig', [
        'home' => $home,
    ]);
}

Template

{% extends 'layout.html.twig' %}
{% block title %} Fuzz Design {% endblock title %}
{% block stylesheets %}
    <link rel="stylesheet" type="text/css" href="{{ 'homepage.css' }}">
{% endblock stylesheets %}
{% block body %} .... {% endblock %}

And here is the MainController portion for a page displaying the CSS instead :

/**
* @Route("/about", name="about")
*/
public function about()
{
    $about = $this->getDoctrine()
        ->getRepository(About::class)
        ->find(1);

    $projets = $this->getDoctrine()
        ->getRepository(Project::class)
        ->findBy(
            array(),
            array('id' => 'DESC'),
            3
        );

    return $this->render('main/about.html.twig', [
        'about' => $about,
        'projets'=>$projets,
    ]);
}

Template

{% extends 'layout.html.twig' %}
{% block title %}Fuzz Design : A Propos{% endblock %}
{% block stylesheets %}
    <link rel="stylesheet" type="text/css" href="{{ 'about.css' }}">
    <link rel="stylesheet" type="text/css" href="{{ 'animation_hover.css' }}">
{% endblock %}
{% block body %}.... {% endblock %}

I am almost sure that I do it the same way, but the first one displays the template, when the other displays the css stylesheet code.

Has anyone any idea of the reason why I obtain such a weird behavior ? And how to fix it ?


Solution

  • It could be a name conflict.

    Try to change the name of your css file like : banana.css and make the corresponding call in your template.

    It could work =)