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 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题