[英]Symfony/Twig can't extend a template when displaying a grid with APYDataGridBundle
我有一个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>
您只需要将grid
放在base.html.twig
中的一个块中即可。
{% extends '::base.html.twig' %}
{% block body %}
{{ grid(grid) }}
{% endblock %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.