Symfony 3 - 模板“SonataPageBundle::base_error.html.twig”上的块“标题”不存在

Posted

技术标签:

【中文标题】Symfony 3 - 模板“SonataPageBundle::base_error.html.twig”上的块“标题”不存在【英文标题】:Symfony 3 - Block "title" on template "SonataPageBundle::base_error.html.twig" does not exist 【发布时间】:2018-02-12 05:53:06 【问题描述】:

我在模板“SonataPageBundle::base_error.html.twig”上遇到错误“块”标题“不存在。 " 当我试图访问http://localhost:8000/ 时。我正在尝试启动一个配置了奏鸣曲管理包和奏鸣曲页面包的项目,这些是我的项目在 symfony (composer.json) 中的一些依赖项:

php 7.1.8 Symfony 3.3.8

 "require": 
                "doctrine/doctrine-bundle": "^1.6",
                "doctrine/orm": "^2.5",
                "friendsofsymfony/rest-bundle": "^2.2",
                "incenteev/composer-parameter-handler": "^2.0",
                "sensio/distribution-bundle": "^5.0.19",
                "sensio/framework-extra-bundle": "^3.0.2",
                "sonata-project/admin-bundle": "^3.23",
                "sonata-project/cache-bundle": "^2.3",
                "sonata-project/datagrid-bundle": "^2.2",
                "sonata-project/doctrine-orm-admin-bundle": "^3.1",
                "sonata-project/easy-extends-bundle": "^2.2",
                "sonata-project/notification-bundle": "^3.1",
                "sonata-project/page-bundle": "^3.5",
                "sonata-project/seo-bundle": "^2.2",
                "symfony-cmf/routing-bundle": "^2.0",
                "symfony/monolog-bundle": "^3.1.0",
                "symfony/polyfill-apcu": "^1.0",
                "symfony/swiftmailer-bundle": "^2.3.10",
                "symfony/symfony": "3.3.*",
                "twig/twig": "^1.0||^2.0"
            ,

这是错误堆栈跟踪:

Twig_Error_Runtime:
Block "title" on template "SonataPageBundle::base_error.html.twig" does not exist.

  at vendor\sonata-project\page-bundle\Resources\views\base_error.html.twig:11
  at Twig_Template->displayBlock('title', array('exception' => object(InternalErrorException), 'wrap_fields_with_addons' => true, 'app' => object(AppVariable), 'sonata_block' => object(GlobalVariables), 'sonata_admin' => object(GlobalVariables), 'sonata_page' => object(GlobalVariables)), array('page_stylesheets' => array(object(__TwigTemplate_626d3c7ea09d945dea3e3ced9062d6a059ed90c3731a85afe587b65d9135355b), 'block_page_stylesheets'), 'content' => array(object(__TwigTemplate_92a22adb7096a00b0799bd4759bdde6bb47abc78e12c93295c06f6a96de5ba5a), 'block_content')), true)
     (vendor\twig\twig\lib\Twig\Template.php:254)
  at Twig_Template->renderBlock('title', array('exception' => object(InternalErrorException), 'wrap_fields_with_addons' => true, 'app' => object(AppVariable), 'sonata_block' => object(GlobalVariables), 'sonata_admin' => object(GlobalVariables), 'sonata_page' => object(GlobalVariables)), array('page_stylesheets' => array(object(__TwigTemplate_626d3c7ea09d945dea3e3ced9062d6a059ed90c3731a85afe587b65d9135355b), 'block_page_stylesheets'), 'content' => array(object(__TwigTemplate_92a22adb7096a00b0799bd4759bdde6bb47abc78e12c93295c06f6a96de5ba5a), 'block_content')))
     (var\cache\dev\twig\a4\a4a167564b475b5c6ead2ae566a2cfcbb882dc2de2df7ff848f92fa5b57b1a21.php:27)
  at __TwigTemplate_626d3c7ea09d945dea3e3ced9062d6a059ed90c3731a85afe587b65d9135355b->doDisplay(array('exception' => object(InternalErrorException), 'wrap_fields_with_addons' => true, 'app' => object(AppVariable), 'sonata_block' => object(GlobalVariables), 'sonata_admin' => object(GlobalVariables), 'sonata_page' => object(GlobalVariables)), array('page_stylesheets' => array(object(__TwigTemplate_626d3c7ea09d945dea3e3ced9062d6a059ed90c3731a85afe587b65d9135355b), 'block_page_stylesheets'), 'content' => array(object(__TwigTemplate_92a22adb7096a00b0799bd4759bdde6bb47abc78e12c93295c06f6a96de5ba5a), 'block_content')))
     (vendor\twig\twig\lib\Twig\Template.php:389)
  at Twig_Template->displayWithErrorHandling(array('exception' => object(InternalErrorException), 'wrap_fields_with_addons' => true, 'app' => object(AppVariable), 'sonata_block' => object(GlobalVariables), 'sonata_admin' => object(GlobalVariables), 'sonata_page' => object(GlobalVariables)), array('page_stylesheets' => array(object(__TwigTemplate_626d3c7ea09d945dea3e3ced9062d6a059ed90c3731a85afe587b65d9135355b), 'block_page_stylesheets'), 'content' => array(object(__TwigTemplate_92a22adb7096a00b0799bd4759bdde6bb47abc78e12c93295c06f6a96de5ba5a), 'block_content')))
     (vendor\twig\twig\lib\Twig\Template.php:366)
  at Twig_Template->display(array('exception' => object(InternalErrorException), 'wrap_fields_with_addons' => true, 'app' => object(AppVariable), 'sonata_block' => object(GlobalVariables), 'sonata_admin' => object(GlobalVariables), 'sonata_page' => object(GlobalVariables)), array('content' => array(object(__TwigTemplate_92a22adb7096a00b0799bd4759bdde6bb47abc78e12c93295c06f6a96de5ba5a), 'block_content')))
     (var\cache\dev\twig\89\8910d15eec17e5054a2c6abc9ebc366c887c2ca4519f4cc11e0a2a9ab49f42c3.php:30)
  at __TwigTemplate_92a22adb7096a00b0799bd4759bdde6bb47abc78e12c93295c06f6a96de5ba5a->doDisplay(array('exception' => object(InternalErrorException), 'wrap_fields_with_addons' => true, 'app' => object(AppVariable), 'sonata_block' => object(GlobalVariables), 'sonata_admin' => object(GlobalVariables), 'sonata_page' => object(GlobalVariables)), array('content' => array(object(__TwigTemplate_92a22adb7096a00b0799bd4759bdde6bb47abc78e12c93295c06f6a96de5ba5a), 'block_content')))
     (vendor\twig\twig\lib\Twig\Template.php:389)
  at Twig_Template->displayWithErrorHandling(array('exception' => object(InternalErrorException), 'wrap_fields_with_addons' => true, 'app' => object(AppVariable), 'sonata_block' => object(GlobalVariables), 'sonata_admin' => object(GlobalVariables), 'sonata_page' => object(GlobalVariables)), array('content' => array(object(__TwigTemplate_92a22adb7096a00b0799bd4759bdde6bb47abc78e12c93295c06f6a96de5ba5a), 'block_content')))
     (vendor\twig\twig\lib\Twig\Template.php:366)
  at Twig_Template->display(array('exception' => object(InternalErrorException)))
     (vendor\twig\twig\lib\Twig\Template.php:374)
  at Twig_Template->render(array('exception' => object(InternalErrorException)))
     (vendor\symfony\symfony\src\Symfony\Bridge\Twig\TwigEngine.php:49)
  at Symfony\Bridge\Twig\TwigEngine->render('SonataPageBundle::internal_error.html.twig', array('exception' => object(InternalErrorException)))
     (vendor\symfony\symfony\src\Symfony\Bundle\TwigBundle\TwigEngine.php:45)
  at Symfony\Bundle\TwigBundle\TwigEngine->render('SonataPageBundle::internal_error.html.twig', array('exception' => object(InternalErrorException)))
     (vendor\sonata-project\page-bundle\Listener\ExceptionListener.php:192)
  at Sonata\PageBundle\Listener\ExceptionListener->handleInternalError(object(GetResponseForExceptionEvent))
     (vendor\sonata-project\page-bundle\Listener\ExceptionListener.php:178)
  at Sonata\PageBundle\Listener\ExceptionListener->onKernelException(object(GetResponseForExceptionEvent), 'kernel.exception', object(TraceableEventDispatcher))
  at call_user_func(array(object(ExceptionListener), 'onKernelException'), object(GetResponseForExceptionEvent), 'kernel.exception', object(TraceableEventDispatcher))
     (vendor\symfony\symfony\src\Symfony\Component\EventDispatcher\Debug\WrappedListener.php:104)
  at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(object(GetResponseForExceptionEvent), 'kernel.exception', object(ContainerAwareEventDispatcher))
  at call_user_func(object(WrappedListener), object(GetResponseForExceptionEvent), 'kernel.exception', object(ContainerAwareEventDispatcher))
     (vendor\symfony\symfony\src\Symfony\Component\EventDispatcher\EventDispatcher.php:212)
  at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.exception', object(GetResponseForExceptionEvent))
     (vendor\symfony\symfony\src\Symfony\Component\EventDispatcher\EventDispatcher.php:44)
  at Symfony\Component\EventDispatcher\EventDispatcher->dispatch('kernel.exception', object(GetResponseForExceptionEvent))
     (vendor\symfony\symfony\src\Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher.php:146)
  at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch('kernel.exception', object(GetResponseForExceptionEvent))
     (vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php:230)
  at Symfony\Component\HttpKernel\HttpKernel->handleException(object(InternalErrorException), object(Request), 1)
     (vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php:79)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php:171)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (web\app_dev.php:29)
  at require('C:\\...

【问题讨论】:

【参考方案1】:

这是 SonataPageBundle 提供的模板中的错误(请参阅https://github.com/sonata-project/SonataPageBundle/pull/860)。作为一种解决方法,您可以将 Twig 安装降级到 1.x:

composer update --with-dependencies twig/twig:^1.34

【讨论】:

以上是关于Symfony 3 - 模板“SonataPageBundle::base_error.html.twig”上的块“标题”不存在的主要内容,如果未能解决你的问题,请参考以下文章

Symfony 3 - 模板“SonataPageBundle::base_error.html.twig”上的块“标题”不存在

如何在 Sonata Admin(Symfony 3.3、PHP 7)中使用自定义 javascript 为模态窗口扩展模板?

Symfony2 Assetic + Twig 模板 JavaScript 继承

如何在 Sonata/Symfony 3.3 中设置内容配置?

Symfony 4 中的奏鸣曲媒体包模板

Symfony 4.4 - 自定义错误模板不起作用