其他分享
首页 > 其他分享> > 模板中的Twig函数“渲染”在哪里消失了?

模板中的Twig函数“渲染”在哪里消失了?

作者:互联网

我刚刚为我的Silex应用程序更新了我的依赖关系,现在突然我的模板之一因错误而失败:

Twig_Error_Syntax: The function "render" does not exist.

在执行作曲家更新之前,这工作正常.从作曲家的输出中,以下内容已更新:

- 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}}’的任何模板都可以正常工作.

解决方法:

我有同样的问题.在注册Web Profiler之前是否注册了HttpFragmentServiceProvider?它并不明显,但是文档中提到了here.它对我来说很好用.

问候

标签:silex,twig,php
来源: https://codeday.me/bug/20191028/1950942.html