Where did the Twig function "render" disappear in templates?
I just updated my dependencies for my Silex app and now suddenly one of my templates fails with the error:
Twig_Error_Syntax: The function "render" does not exist.
This worked great before I executed composer update
. The composer's output has been updated:
- 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%
The code that worked in my template:
{{ render (url('navigation')) | raw }}
I can't find anything that suggests this feature has been deprecated or replaced it. I'm not sure which of the updates caused this issue, but I suspect it's Twig-Bridge. I am using Twig version 1.18.1.
I'm a little bit obsessed with the problem here and it is giving me some trouble, so any help would be great.
I acknowledge the fact that I had to link the version of the packages I am using so that I can test the updates in a more methodical way.
Thanks Russell
Update 1:
Update to provide some more contexts.
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"
}
I register Twig and UrlGenerator services using the following:
$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;
}));
The twig itself still works, and any template that doesn't have {{render}} in it will work without issue.
source to share
Make sure you have:
-
twig/twig
(You might have uninstalled it before doing composer update) andsymfony/twig-bridge
installed with composer.
and -
Register
TwigServiceProvider()
andUrlGeneratorServiceProvider()
$app->register(new Silex\Provider\TwigServiceProvider(), array( 'twig.path' => \__DIR__.'/path/to/templates/', )); $app->register(new UrlGeneratorServiceProvider());
source to share