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

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?