douzhe9075
2019-03-13 16:15
浏览 62
已采纳

Symfony 4 - 显示模板问题css

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 ?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsdapobp26141 2019-03-14 12:52
    已采纳

    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 =)

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题