模板中的 Twig 函数 'render' 去哪儿了?
Where has the Twig function 'render' in templates gone?
我刚刚更新了我的 Silex 应用程序的依赖项,现在我的一个模板突然失败并出现错误:
Twig_Error_Syntax: The function "render" does not exist.
在我执行 composer update
之前,它运行良好。从作曲家的输出中更新了以下内容:
- Removing symfony/options-resolver (v2.6.7)
- Installing symfony/options-resolver (v2.7.0)
Downloading: 100%
- Removing symfony/intl (v2.6.7)
- Installing symfony/intl (v2.7.0)
Downloading: 100%
- Removing symfony/form (v2.6.7)
- Installing symfony/form (v2.7.0)
Downloading: 100%
- Removing symfony/translation (v2.6.7)
- Installing symfony/translation (v2.7.0)
Downloading: 100%
- Removing symfony/validator (v2.6.7)
- Installing symfony/validator (v2.7.0)
Downloading: 100%
- Removing symfony/security (v2.6.7)
- Installing symfony/security (v2.7.0)
Downloading: 100%
- Removing symfony/finder (v2.6.7)
- Installing symfony/finder (v2.7.0)
Downloading: 100%
- Removing symfony/process (v2.6.7)
- Installing symfony/process (v2.7.0)
Downloading: 100%
- Removing symfony/twig-bridge (v2.6.7)
- Installing symfony/twig-bridge (v2.7.0)
Downloading: 100%
- Removing symfony/web-profiler-bundle (v2.6.7)
- Installing symfony/web-profiler-bundle (v2.7.0)
Downloading: 100%
- Removing symfony/stopwatch (v2.6.7)
- Installing symfony/stopwatch (v2.7.0)
Downloading: 100%
在我的模板中运行的代码是:
{{ render (url('navigation')) | raw }}
我找不到任何表明此功能已被弃用或已被替换的信息。我不确定是哪个更新导致了这个问题,但我怀疑是 Twig-Bridge。我正在使用 Twig 版本 1.18.1.
我对这里的问题有点困惑,它给我带来了一些问题,所以任何帮助都会很好。
我承认我应该确定我正在使用的软件包的版本,这样我就可以更有条不紊地测试升级。
谢谢拉塞尔
更新 1:
提供更多上下文的更新。
composer.json
"require": {
"silex/silex": "~1.2",
"silex/web-profiler": "1.0.*@dev",
"ruflin/elastica": "1.3.*@dev",
"dflydev/doctrine-orm-service-provider": "1.0.*@dev",
"monolog/monolog": "1.9.1",
"twig/twig": "1.18.*@dev",
"twig/extensions": "1.2.*@dev",
"symfony/yaml": "~2.4",
"symfony/console": "~2.4",
"symfony/twig-bridge": "~2.4",
"symfony/config": "~2.4",
"symfony/monolog-bridge": "~2.4",
"symfony/serializer": "~2.4",
"symfony/form": "~2.4",
"symfony/validator": "~2.4",
"symfony/translation": "~2.4",
"symfony/security": "~2.4",
"macedigital/silex-jms-serializer": "1.0.0",
"jdesrosiers/silex-jms-serializer-provider": "~0.1",
"mheap/silex-gravatar": "dev-master",
"mheap/gravatar-php": "dev-master",
"mheap/silex-assetic": "1.0.4",
"knplabs/knp-menu": "2.0.*@dev",
"predis/service-provider": "dev-master",
"pear/archive_tar": "dev-master",
"pear/pear_exception": "1.0.*@dev",
"wapmorgan/unified-archive": "dev-master",
"sybio/image-workshop": "dev-master",
"sybio/gif-frame-extractor": "dev-master",
"sybio/gif-creator": "dev-master",
"paypal/rest-api-sdk-php" : "*",
"kilte/silex-pagination": "1.1.*@dev",
"thispagecannotbefound/silex-markdown-parser": "dev-master",
"erusev/parsedown": "~1.4",
"erusev/parsedown-extra": "dev-master"
}
我使用以下方法注册 Twig 和 UrlGenerator 服务:
$app->register ( new \Silex\Provider\UrlGeneratorServiceProvider () );
$app -> register (new \Silex\Provider\TwigServiceProvider(), array(
'twig.options' => array("debug" => true)
));
$app['twig'] = $app -> share($app -> extend('twig', function($twig, $app) {
$twig -> addExtension(new \Twig_Extension_Debug());
return $twig;
}));
Twig 本身仍在工作,任何没有“{{ render }}”的模板都可以正常工作。
确保你有:
twig/twig
(也许您在执行 composer 更新之前删除了它)并且 symfony/twig-bridge
通过 composer 安装。
和
注册TwigServiceProvider()
和UrlGeneratorServiceProvider()
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => \__DIR__.'/path/to/templates/',
));
$app->register(new UrlGeneratorServiceProvider());
我遇到了同样的问题。您是否在注册 Web Profiler 之前注册了 HttpFragmentServiceProvider?这并不明显,但文档中提到了它 here。它对我来说效果很好。
此致
我刚刚更新了我的 Silex 应用程序的依赖项,现在我的一个模板突然失败并出现错误:
Twig_Error_Syntax: The function "render" does not exist.
在我执行 composer update
之前,它运行良好。从作曲家的输出中更新了以下内容:
- Removing symfony/options-resolver (v2.6.7)
- Installing symfony/options-resolver (v2.7.0)
Downloading: 100%
- Removing symfony/intl (v2.6.7)
- Installing symfony/intl (v2.7.0)
Downloading: 100%
- Removing symfony/form (v2.6.7)
- Installing symfony/form (v2.7.0)
Downloading: 100%
- Removing symfony/translation (v2.6.7)
- Installing symfony/translation (v2.7.0)
Downloading: 100%
- Removing symfony/validator (v2.6.7)
- Installing symfony/validator (v2.7.0)
Downloading: 100%
- Removing symfony/security (v2.6.7)
- Installing symfony/security (v2.7.0)
Downloading: 100%
- Removing symfony/finder (v2.6.7)
- Installing symfony/finder (v2.7.0)
Downloading: 100%
- Removing symfony/process (v2.6.7)
- Installing symfony/process (v2.7.0)
Downloading: 100%
- Removing symfony/twig-bridge (v2.6.7)
- Installing symfony/twig-bridge (v2.7.0)
Downloading: 100%
- Removing symfony/web-profiler-bundle (v2.6.7)
- Installing symfony/web-profiler-bundle (v2.7.0)
Downloading: 100%
- Removing symfony/stopwatch (v2.6.7)
- Installing symfony/stopwatch (v2.7.0)
Downloading: 100%
在我的模板中运行的代码是:
{{ render (url('navigation')) | raw }}
我找不到任何表明此功能已被弃用或已被替换的信息。我不确定是哪个更新导致了这个问题,但我怀疑是 Twig-Bridge。我正在使用 Twig 版本 1.18.1.
我对这里的问题有点困惑,它给我带来了一些问题,所以任何帮助都会很好。
我承认我应该确定我正在使用的软件包的版本,这样我就可以更有条不紊地测试升级。
谢谢拉塞尔
更新 1:
提供更多上下文的更新。
composer.json
"require": {
"silex/silex": "~1.2",
"silex/web-profiler": "1.0.*@dev",
"ruflin/elastica": "1.3.*@dev",
"dflydev/doctrine-orm-service-provider": "1.0.*@dev",
"monolog/monolog": "1.9.1",
"twig/twig": "1.18.*@dev",
"twig/extensions": "1.2.*@dev",
"symfony/yaml": "~2.4",
"symfony/console": "~2.4",
"symfony/twig-bridge": "~2.4",
"symfony/config": "~2.4",
"symfony/monolog-bridge": "~2.4",
"symfony/serializer": "~2.4",
"symfony/form": "~2.4",
"symfony/validator": "~2.4",
"symfony/translation": "~2.4",
"symfony/security": "~2.4",
"macedigital/silex-jms-serializer": "1.0.0",
"jdesrosiers/silex-jms-serializer-provider": "~0.1",
"mheap/silex-gravatar": "dev-master",
"mheap/gravatar-php": "dev-master",
"mheap/silex-assetic": "1.0.4",
"knplabs/knp-menu": "2.0.*@dev",
"predis/service-provider": "dev-master",
"pear/archive_tar": "dev-master",
"pear/pear_exception": "1.0.*@dev",
"wapmorgan/unified-archive": "dev-master",
"sybio/image-workshop": "dev-master",
"sybio/gif-frame-extractor": "dev-master",
"sybio/gif-creator": "dev-master",
"paypal/rest-api-sdk-php" : "*",
"kilte/silex-pagination": "1.1.*@dev",
"thispagecannotbefound/silex-markdown-parser": "dev-master",
"erusev/parsedown": "~1.4",
"erusev/parsedown-extra": "dev-master"
}
我使用以下方法注册 Twig 和 UrlGenerator 服务:
$app->register ( new \Silex\Provider\UrlGeneratorServiceProvider () );
$app -> register (new \Silex\Provider\TwigServiceProvider(), array(
'twig.options' => array("debug" => true)
));
$app['twig'] = $app -> share($app -> extend('twig', function($twig, $app) {
$twig -> addExtension(new \Twig_Extension_Debug());
return $twig;
}));
Twig 本身仍在工作,任何没有“{{ render }}”的模板都可以正常工作。
确保你有:
twig/twig
(也许您在执行 composer 更新之前删除了它)并且symfony/twig-bridge
通过 composer 安装。
和注册
TwigServiceProvider()
和UrlGeneratorServiceProvider()
$app->register(new Silex\Provider\TwigServiceProvider(), array( 'twig.path' => \__DIR__.'/path/to/templates/', )); $app->register(new UrlGeneratorServiceProvider());
我遇到了同样的问题。您是否在注册 Web Profiler 之前注册了 HttpFragmentServiceProvider?这并不明显,但文档中提到了它 here。它对我来说效果很好。
此致