Note that there are some explanatory texts on larger screens.

plurals
  1. POSilex - Twig_Error_Syntax: The function "path" does not exist
    primarykey
    data
    text
    <p>According to the <a href="http://silex.sensiolabs.org/doc/providers/twig.html#symfony2-components-integration" rel="noreferrer">Silex documentation</a>:</p> <blockquote> <p>Symfony provides a Twig bridge that provides additional integration between some Symfony2 components and Twig. Add it as a dependency to your composer.json file.</p> </blockquote> <p>I include the following in my <code>composer.json</code> file:</p> <pre><code>{ "require": { "silex/silex": "1.*", "twig/twig": "&gt;=1.8,&lt;2.0-dev", "symfony/twig-bridge": "2.3.*" } } </code></pre> <p>I register the <code>TwigServiceProvider()</code> like so:</p> <pre><code>$app-&gt;register(new Silex\Provider\TwigServiceProvider(), array( 'twig.path' =&gt; __DIR__ . '/views' )); </code></pre> <p>I'm attempting to use the twig <code>path()</code> method like so:</p> <pre><code>&lt;a href="{{ path('logout') }}"&gt;Log out&lt;/a&gt; </code></pre> <p>The error I get is as follows:</p> <blockquote> <p>Twig_Error_Syntax: The function "path" does not exist</p> </blockquote> <p><strong>Why am I getting this error?</strong></p> <ul> <li>I have tried switching around versions to check if it is a version issue</li> <li>One google groups comment suggested 'registering' the twig bridge provider, but this doesn't exist</li> <li>I <em>don't</em> want to have to use: <code>app.url_generator.generate</code> in all my templates instead</li> </ul> <hr> <h2>A temporary solution I have found:</h2> <p>Ensure The <code>UrlGeneratorServiceProvider()</code> is registered:</p> <pre><code>$app-&gt;register(new UrlGeneratorServiceProvider()); </code></pre> <p>Create a new function for twig for <code>path()</code>:</p> <pre><code>$app['twig']-&gt;addFunction(new \Twig_SimpleFunction('path', function($url) use ($app) { return $app['url_generator']-&gt;generate($url); })); </code></pre> <p><strong>I shouldn't have to do this!!</strong> How can I get this working <em>properly</em>?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload