我在 app / Resources / homepage 中有一个名为 homepage.html.twig 的树枝模板。 我试图以这种方式使用HomeController渲染此模板:
<?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');
}
}
这是树枝模板:
{% 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 »</a>
</p>
</div>
</div>
{% endblock %}
为什么渲染此模板不起作用?
答案 0 :(得分:1)
我通过添加
来解决问题{% block body %}
{% endblock %}
base.html.twig中的