3

I have just updated my dependencies for my Silex application and now suddenly one of my templates is failing with the error:

Twig_Error_Syntax: The function "render" does not exist.

This was working fine before I performed a composer update. From the composer output the following have 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 was working within my template is:

{{ render (url('navigation')) | raw }}

I cannot find anything that suggests this function has been deprecated or what it has been replaced with. I am not sure which of the updates has caused this problem, but i suspect it is Twig-Bridge. I am using Twig version 1.18.1.

I am a bit stuck as to what the issue is here and it is causing me some problems so any help would be great.

I acknowlegde the fact that I should have pegged the version of the packages I am using so I can test upgrades in a more methodical manner.

Thanks, Russell

Update 1:

An update to provide some more context.

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 the 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;
    }));

Twig itself is still working and any template that does not have '{{ render }}' in it will work without issue.

Russell Seymour
  • 1,333
  • 1
  • 16
  • 35

2 Answers2

4

I had the same problem. Did you register HttpFragmentServiceProvider before registering the Web Profiler? It is not obvious, but the documentation mentions about it here. It worked nicely for me.

Regards

Szyku
  • 56
  • 3
0

Make sure you have:

  • twig/twig (Maybe you have deleted it before performing composer update) and symfony/twig-bridge installed via composer.
    and
  • Register TwigServiceProvider() and UrlGeneratorServiceProvider()

    $app->register(new Silex\Provider\TwigServiceProvider(), array(  
      'twig.path' => \__DIR__.'/path/to/templates/',  
    ));
    
    $app->register(new UrlGeneratorServiceProvider());
    

     

Med
  • 2,035
  • 20
  • 31
doncredas
  • 161
  • 7
  • 1
    Thanks for this. I do still have ```twig/twig``` and ```symfony/twig-bridge``` in my composer.json file. The two services are registered. I will update my original question with these bits. – Russell Seymour Jun 05 '15 at 14:05