使用APYDataGridBundle显示网格时,Symfony / Twig无法扩展模板

时间:2013-09-27 00:21:59

标签: php symfony twig

我有一个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) }}

会导致此错误:扩展另一个模板的模板在TestTranspoBundle中无法使用正文:程序:第2行的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>

1 个答案:

答案 0 :(得分:7)

您只需将grid放在base.html.twig

的一个区块中即可
{% extends '::base.html.twig' %}
{% block body %}
    {{ grid(grid) }}
{% endblock %}