我有一个 base.html.twig 模板,我已经在 index.html.twig 文件中成功扩展了它,我认为这意味着 base.html.twig 文件格式正确并且被正确调用(这是我的第二天Symfony,请多多包涵。)我成功安装了 APYDataGridBundle 并能够在一个空模板中显示一个网格:
{{ grid(grid) }}
但是当我在 index.html.twig 中扩展 base.html.twig 时,我得到一个错误。编码:
{% extends '::base.html.twig' %}
{{ grid(grid) }}
导致此错误:扩展另一个模板的模板在第 2 行的 TestTranspoBundle:Programs:index.html.twig 中不能有正文。
我在 APYDataGridBundle 问题中没有看到任何关于此的内容,如果这是他们的错而不是我的用户错误,这似乎是一个大问题。所以我希望我只是犯了一个新手错误。
这是调用模板的控制器:
namespace Test\TranspoBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use APY\DataGridBundle\Grid\Source\Entity;
class ProgramsController extends Controller
{
public function indexAction()
{
$source = new Entity('TestTranspoBundle:Programs');
$grid = $this->get('grid');
$grid->setSource($source);
$grid->isReadyForRedirect();
return $this->render('TestTranspoBundle:Programs:index.html.twig', array('grid' => $grid));
}
}
这是base.html.twig:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{% block title %}My System - Symfony{% endblock %}</title>
{% block stylesheets %}
<!-- blueprint CSS framework -->
<link rel="stylesheet" type="text/css" href="{{ asset('bundles/testtranspo/css/screen.css') }}" media="screen, projection" >
<link rel="stylesheet" type="text/css" href="{{ asset('bundles/testtranspo/css/print.css') }}" media="print" >
<!--[if lt IE 8]>
<link rel="stylesheet" type="text/css" href="{{ asset('bundles/testtranspo/css/ie.css') }}" media="screen, projection" >
<![endif]-->
<link rel="stylesheet" type="text/css" href="{{ asset('bundles/testtranspo/css/main.css') }}" >
<link rel="stylesheet" type="text/css" href="{{ asset('bundles/testtranspo/css/form.css') }}" >
{% endblock %}
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
</head>
<body>
<div class="container" id="page">
<div id="header">
<div id="logo">
<span>My System</span>
<span id="logout">Hi, Logged In User. <a href="https://weblogin.umich.edu/cgi-bin/logout">Log out.</a>
</span>
</div>
</div>
<div id="mainmenu">
{% block sidebar %}
<ul>
<li class="first" id="nav-people"><a href="{{ path('_people_index') }}">People</a></li>
<li class="first" id="nav-reservations"><a href="{{ path('_reservations_index') }}">Reservations</a></li>
<li class="first" id="nav-vehicles"><a href="{{ path('_vehicles_index') }}">Vehicles</a></li>
<li class="first" id="nav-programs"><a href="{{ path('_programs_index') }}">Programs</a></li>
<li class="first" id="nav-destinations"><a href="{{ path('_destinations_index') }}">Destinations</a></li>
<li class="first" id="nav-reports"><a href="{{ path('_reports_index') }}">Reports</a></li>
{% if TRUE %}
<li class="first" id="nav-installation"><a href="{{ path('_installation_update') }}">Site On/Off</a></li>
{% endif %}
</ul>
{% endblock %}
</div>
<div id="content">
{% block body %}{% endblock %}
</div>
</div>
{% block javascripts %}{% endblock %}
</body>
</html>