function TwigExtension::getFunctions

Same name in this branch
  1. 11.x core/modules/sdc/src/Twig/TwigExtension.php \Drupal\sdc\Twig\TwigExtension::getFunctions()
Same name in other branches
  1. 9 core/lib/Drupal/Core/Template/TwigExtension.php \Drupal\Core\Template\TwigExtension::getFunctions()
  2. 8.9.x core/lib/Drupal/Core/Template/TwigExtension.php \Drupal\Core\Template\TwigExtension::getFunctions()
  3. 10 core/modules/sdc/src/Twig/TwigExtension.php \Drupal\sdc\Twig\TwigExtension::getFunctions()
  4. 10 core/lib/Drupal/Core/Template/TwigExtension.php \Drupal\Core\Template\TwigExtension::getFunctions()

File

core/lib/Drupal/Core/Template/TwigExtension.php, line 98

Class

TwigExtension
A class providing Drupal Twig extensions.

Namespace

Drupal\Core\Template

Code

public function getFunctions() {
    return [
        // This function will receive a renderable array, if an array is detected.
new TwigFunction('render_var', [
            $this,
            'renderVar',
        ]),
        // The URL and path function are defined in close parallel to those found
        // in \Symfony\Bridge\Twig\Extension\RoutingExtension
new TwigFunction('url', [
            $this,
            'getUrl',
        ], [
            'is_safe_callback' => [
                $this,
                'isUrlGenerationSafe',
            ],
        ]),
        new TwigFunction('path', [
            $this,
            'getPath',
        ], [
            'is_safe_callback' => [
                $this,
                'isUrlGenerationSafe',
            ],
        ]),
        new TwigFunction('link', [
            $this,
            'getLink',
        ]),
        new TwigFunction('file_url', [
            $this,
            'getFileUrl',
        ]),
        new TwigFunction('attach_library', [
            $this,
            'attachLibrary',
        ]),
        new TwigFunction('active_theme_path', [
            $this,
            'getActiveThemePath',
        ]),
        new TwigFunction('active_theme', [
            $this,
            'getActiveTheme',
        ]),
        new TwigFunction('create_attribute', [
            $this,
            'createAttribute',
        ]),
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.