Symfony/Twig can't extend a template when displaying a grid with APYDataGridBundle
NickName:Erica Ackerman Ask DateTime:2013-09-27T08:21:58

Symfony/Twig can't extend a template when displaying a grid with APYDataGridBundle

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

More about “Symfony/Twig can't extend a template when displaying a grid with APYDataGridBundle” related questions

Integrating Symfony Routing and Twig using Symfony Twig Bridge

I use in my code Twig and Symfony routing which I would like to integrate with Twig using Symfony Twig Bridge. I have them both installed and what I need to do is to add to Twig extensions Symfony\

Show Detail

can symfony 2.8 updated with twig 2.4.4?

Currently the application have symfony 2.8.42 and twig version 1.35.3. Due to some security issue in twig we need to upgrade twig to 2.4.4 and above. But I am not sure as what else will be broken o...

Show Detail

Symfony translator and Twig

I have a templates library based on Twig, but I have not installed the whole Symfony library. I want to use Symfony's translation in my project, is this possible without installing the whole Symfony?

Show Detail

Sonata Admin for Symfony 4.4 not possible install twig/twig conflict

I run new project Symfony 4.4 symfony new new_project --version=4.4 then composer require sonata-project/admin-bundle and get errors composer require sonata-project/admin-bundle Using version ^3.72...

Show Detail

Using symfony version of a twig extension without Symfony?

It all started with some efforts to localize a website. I was using Twig along with its I18n extension. $extensions[] = new Twig_Extensions_Extension_I18n(); foreach ($extensions as $extension) { $

Show Detail

Symfony 2.8 injecting twig

Pre-note: I am learning Symfony from a Drupal 7 background. I have created a custom model (although I think they are called services in Symfony from what I have read), and would like it to render an

Show Detail

Symfony 4.1 twig extension

In Symfony 4.1 I created an twig extension and I tried to use it as an service twig.extension.active.algos: class: App\Twig\AppExtension public: true tags: - { name: twig.exte...

Show Detail

symfony 4, controller, twig relationship

I have built a framework from scratch using the following article series: http://symfony.com/doc/current/create_framework/index.html Now I have downloaded twig and got templates for it and got these

Show Detail

Symfony - twig - Autoloader expected class

I have a problem with symfony and apparently twig. I've been working on a project for some time, and as I was about to make a new release (by uploading everything througn ftp, following this : http...

Show Detail

Symfony & twig minify html with nochso/html-compress-twig

As I have seen on How can I minify HTML with Twig? Recommends to use the https://github.com/nochso/html-compress-twig to minify the generated html from Twig templates. But on documentation it sho...

Show Detail