Twig Editor does not respect Twig Extensions

PHP Tools [?] extends Visual Studio with set of advanced features to work more efficiently with PHP code.

Twig Editor does not respect Twig Extensions

Postby EraYaN » May 5th, 2018, 5:25 am

I setup my Twig like this currently. (Using Slim v3)

Code: Select all
$container['view'] = function ($c) {
    $view = new \Slim\Views\Twig('twig-templates', [
        'cache' => $c['settings']['caching'],
        'debug' => $c['settings']['debug']
    // Instantiate and add Slim specific extension
    $view->addExtension(new \Slim\Views\TwigExtension($c['router'], $c['request']->getUri()));
    $view->addExtension(new Twig_Extensions_Extension_I18n());
        $view->addExtension(new Twig_Extension_Debug());
    $view->addExtension(new SlugifyExtension(Slugify::create()));
    $twig_env = $view->getEnvironment();
    $twig_env->addGlobal('session', $_SESSION);
    global $cfg;
    $twig_env->addGlobal('cfg', $cfg);
    global $data;
    $twig_env->addGlobal('data', $data);

    return $view;

Now the SimpleFunctions provided by \Slim\Views\TwigExtension all get red squiqqly lines and the SplitView doesn't work at all.

It is a custom fork of the Twig-View componenet: ... ension.php the getFunctions function is correctly implemented.

And the second thing is the 'trans' tag only works in full tag format. Not in the
Code: Select all
{% trans 'Word' %}
syntax, that gives an unexpected token error in the editor. (But it does not happen across the board.)

Is there any way to make this work?
Posts: 9
Joined: June 5th, 2014, 11:06 am

Re: Twig Editor does not respect Twig Extensions

Postby Michal Brabec » May 9th, 2018, 12:47 pm

Hi EraYaN,
thank you for your feedback.
The extension functions from Slim are defined in a composer package, which is not currently analyzed by Twig.
We will add the analysis in the next update.

Symfony extensions for Twig are not yet supported.
We will add the support in the future, but we
Best regards,
Michal Brabec │ DEVSENSE s.r.o. │
User avatar
Michal Brabec
Posts: 11
Joined: September 14th, 2016, 8:55 am

Return to PHP Tools

Who is online

Users browsing this forum: Bing [Bot] and 5 guests

User Control Panel


Who is online

In total there are 6 users online :: 1 registered, 0 hidden and 5 guests (based on users active over the past 5 minutes)
Most users ever online was 77 on September 4th, 2018, 9:46 pm

Users browsing this forum: Bing [Bot] and 5 guests