Page 1 of 1

Twig Editor does not respect Twig Extensions

PostPosted: May 5th, 2018, 5:25 am
by EraYaN
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());
    if($c['settings']['debug'])
        $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: https://github.com/EraYaN/Twig-View/blo ... 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?

Re: Twig Editor does not respect Twig Extensions

PostPosted: May 9th, 2018, 12:47 pm
by Michal Brabec
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