doushang2023 2017-05-02 14:58
浏览 25
已采纳

为什么控制器不渲染树枝模板

I have twig template named homepage.html.twig in app/Resources/homepage. I'm trying to render this template with the HomeController in this way:

 <?php

    namespace AppBundle\Controller;

    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;

    class HomeController extends Controller
    {
        /**
         * @Route("/home", name="homepage")
         * @return \Symfony\Component\HttpFoundation\Response
         */
        public function homeAction()
        {
            return $this->render('homepage/homepage.html.twig');
        }
    }

Here is the twig template:

{% extends 'base.html.twig' %}

{% block body %}
    <div class="container">
        <div class="jumbotron">
            <h1>Navbar example</h1>
            <p>This example is a quick exercise to illustrate how the default, static navbar and fixed to top navbar work. It includes the responsive CSS and HTML, so it also adapts to your viewport and device.</p>
            <p>
                <a class="btn btn-lg btn-primary" href=# role="button">View navbar docs &raquo;</a>
            </p>
        </div>
    </div>
{% endblock %}

Why the rendering of this template is not working ?

  • 写回答

1条回答 默认 最新

  • doujiao9866 2017-05-02 15:04
    关注

    I fixed the problem by putting

    {% block body %}
    {% endblock %}
    

    in the base.html.twig

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

报告相同问题?

悬赏问题

  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入