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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失