error trying to use string-extra functions

Created on 27 February 2024, 4 months ago

Trying to run some of the examples from the twig/string-extra tests, for instance

{{ 'SymfonyStringWithTwig'|u.snake }}

I get a fatal error

Twig\Sandbox\SecurityError: Calling "snake" method on a "Symfony\Component\String\UnicodeString" object is not allowed.

I am using this on a Drupal 9 installation, running Twig 2.15.6, twig/string-extra 3.7.1

What is twig/string-extra vs the string-extra package that is in the main Twig package?

πŸ“Œ Task
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States brad.bulger

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @brad.bulger
  • πŸ‡ΊπŸ‡ΈUnited States jayhuskins

    In order to access the Symfony\Component\String\UnicodeString class in twig, you need to add it as an allowed class in your settings.php with the twig_sandbox_allowed_classes setting. For example:

    $settings['twig_sandbox_allowed_classes'] = [
      'Symfony\Component\String\UnicodeString',
      'Drupal\Core\Template\Attribute',
    ];
    

    See more on how this is processed in the TwigSandboxPolicy.

  • Status changed to Needs work 4 months ago
  • πŸ‡ΊπŸ‡ΈUnited States jayhuskins

    This should be documented on both the module page and the README

Production build 0.69.0 2024