gpt4 book ai didi

php - Twig_Error_Syntax : Unknown "template_from_string" function. 函数已过时?

转载 作者:可可西里 更新时间:2023-11-01 00:56:27 27 4
gpt4 key购买 nike

我记得在 composer 更新后我遇到了这个错误,但之前它运行良好,并且在比较包版本时我没有发现差异。我在模板中以这种方式使用它:

{{ include(template_from_string(page.body)) }}

其中“页面”是来自 Controller 的实体对象。当前版本是:

symfony/symfony                          v2.8.15
twig/extensions v1.4.1
twig/twig v1.30.0

同样在 config.yml 中:

twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
form_themes:
- 'AppBundle::Form/form_override.html.twig'

现在 vendor/twig/twig/lib/twig/Twig/Extension/StringLoader.php 中有视觉上正确的文件,但似乎仍然无法正常工作。完整的堆栈跟踪:

[1] Twig_Error_Syntax: Unknown "template_from_string" function.
at n/a
in ProjectDir\src\AppBundle/Resources/views/Page.html.twig line 22

at Twig_ExpressionParser->getFunctionNodeClass('template_from_string', '22')
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 374

at Twig_ExpressionParser->getFunctionNode('template_from_string', '22')
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 162

at Twig_ExpressionParser->parsePrimaryExpression()
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 102

at Twig_ExpressionParser->getPrimary()
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 55

at Twig_ExpressionParser->parseExpression()
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 520

at Twig_ExpressionParser->parseArguments(true)
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 373

at Twig_ExpressionParser->getFunctionNode('include', '22')
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 162

at Twig_ExpressionParser->parsePrimaryExpression()
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 102

at Twig_ExpressionParser->getPrimary()
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 55

at Twig_ExpressionParser->parseExpression()
in ProjectDir\vendor\twig\twig\lib\Twig\Parser.php line 147

at Twig_Parser->subparse(array(object(Twig_TokenParser_Block), 'decideBlockEnd'), true)
in ProjectDir\vendor\twig\twig\lib\Twig\TokenParser\Block.php line 40

at Twig_TokenParser_Block->parse(object(Twig_Token))
in ProjectDir\vendor\twig\twig\lib\Twig\Parser.php line 190

at Twig_Parser->subparse(null, false)
in ProjectDir\vendor\twig\twig\lib\Twig\Parser.php line 103

at Twig_Parser->parse(object(Twig_TokenStream))
in ProjectDir\app\cache\dev\classes.php line 3415

at Twig_Environment->parse(object(Twig_TokenStream))
in ProjectDir\app\cache\dev\classes.php line 3443

at Twig_Environment->compileSource(object(Twig_Source))
in ProjectDir\app\cache\dev\classes.php line 3291

at Twig_Environment->loadTemplate('AppBundle::Page.html.twig')
in ProjectDir\vendor\symfony\symfony\src\Symfony\Bridge\Twig\TwigEngine.php line 126

at Symfony\Bridge\Twig\TwigEngine->load('AppBundle::Page.html.twig')
in ProjectDir\vendor\symfony\symfony\src\Symfony\Bridge\Twig\TwigEngine.php line 50

at Symfony\Bridge\Twig\TwigEngine->render('AppBundle::Page.html.twig', array('page' => object(Page), 'ads' => array(object(VertBanner), object(VertBanner)), 'slug' => 'direktor'))
in ProjectDir\vendor\symfony\symfony\src\Symfony\Bundle\TwigBundle\TwigEngine.php line 72

at Symfony\Bundle\TwigBundle\TwigEngine->render('AppBundle::Page.html.twig', array('page' => object(Page), 'ads' => array(object(VertBanner), object(VertBanner)), 'slug' => 'direktor'))
in ProjectDir\vendor\symfony\symfony\src\Symfony\Bundle\TwigBundle\TwigEngine.php line 103

at Symfony\Bundle\TwigBundle\TwigEngine->renderResponse('AppBundle::Page.html.twig', array('page' => object(Page), 'ads' => array(object(VertBanner), object(VertBanner)), 'slug' => 'direktor'), null)
in ProjectDir\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Controller\Controller.php line 185

at Symfony\Bundle\FrameworkBundle\Controller\Controller->render('AppBundle::Page.html.twig', array('page' => object(Page), 'ads' => array(object(VertBanner), object(VertBanner)), 'slug' => 'direktor'))
in ProjectDir\src\AppBundle\Controller\PageController.php line 35

at AppBundle\Controller\PageController->getPageAction('direktor')
in line

at call_user_func_array(array(object(PageController), 'getPageAction'), array('direktor'))
in ProjectDir\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php line 144

at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
in ProjectDir\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php line 64

at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
in ProjectDir\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel.php line 69

at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
in ProjectDir\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php line 185

at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
in ProjectDir\web\app_dev.php line 28

at require('ProjectDir\web\app_dev.php')
in ProjectDir\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Resources\config\router_dev.php line 40

最佳答案

您必须让服务容器知道您的 Twig 扩展:

# app/config/services.yml
acme.twig.extension.loader:
class: Twig_Extension_StringLoader
tags:
- { name: 'twig.extension' }

交响乐 4:

# config/services.yml
app.twig.extension.loader:
class: Twig\Extension\StringLoaderExtension
tags:
- { name: 'twig.extension' }

关于php - Twig_Error_Syntax : Unknown "template_from_string" function. 函数已过时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41465428/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com