I have a base.html.twig template that I have successfully extended in an index.html.twig file, which I take to mean that the base.html.twig file is well formed and being called correctly (this is my second day with Symfony, so bear with me.) I successfully installed APYDataGridBundle and am able to display a grid in an otherwise empty template:
{{ grid(grid) }}
But when I extend base.html.twig in index.html.twig, I get an error. The code:
{% extends '::base.html.twig' %}
{{ grid(grid) }}
results in this error: A template that extends another one cannot have a body in TestTranspoBundle:Programs:index.html.twig at line 2.
I don't see anything about this in the APYDataGridBundle issues, and it seems like it would be a big problem if it were their fault rather than user error on my part. So I'm hoping I'm just making a newbie error.
Here is the controller that is calling the template:
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));
}
}
Here is 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>
Copyright Notice:Content Author:「Erica Ackerman」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/19040803/symfony-twig-cant-extend-a-template-when-displaying-a-grid-with-apydatagridbund