TwigFilter example

new DoTokenParser(),
            new EmbedTokenParser(),
            new WithTokenParser(),
            new DeprecatedTokenParser(),
        ];
    }

    public function getFilters(): array
    {
        return [
            // formatting filters             new TwigFilter('date', 'twig_date_format_filter', ['needs_environment' => true]),
            new TwigFilter('date_modify', 'twig_date_modify_filter', ['needs_environment' => true]),
            new TwigFilter('format', 'twig_sprintf'),
            new TwigFilter('replace', 'twig_replace_filter'),
            new TwigFilter('number_format', 'twig_number_format_filter', ['needs_environment' => true]),
            new TwigFilter('abs', 'abs'),
            new TwigFilter('round', 'twig_round'),

            // encoding             new TwigFilter('url_encode', 'twig_urlencode_filter'),
            new TwigFilter('json_encode', 'json_encode'),
            new TwigFilter('convert_encoding', 'twig_convert_encoding'),

            
return [new AutoEscapeTokenParser()];
    }

    public function getNodeVisitors(): array
    {
        return [new EscaperNodeVisitor()];
    }

    public function getFilters(): array
    {
        return [
            new TwigFilter('escape', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']),
            new TwigFilter('e', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']),
            new TwigFilter('raw', 'twig_raw_filter', ['is_safe' => ['all']]),
        ];
    }

    /** * Sets the default strategy to use when not defined by the user. * * The strategy can be a valid PHP callback that takes the template * name as an argument and returns the strategy to use. * * @param string|false|callable $defaultStrategy An escaping strategy */

  public function getFilters() {
    return [
      'testfilter' => new TwigFilter('testfilter', ['Drupal\twig_extension_test\TwigExtension\TestExtension', 'testFilter']),
    ];
  }

  /** * Gets a unique identifier for this Twig extension. * * @return string * A unique identifier for this Twig extension. */
  public function getName() {
    return 'twig_extension_test.test_extension';
  }
new TwigFunction('active_theme', [$this, 'getActiveTheme']),
      new TwigFunction('create_attribute', [$this, 'createAttribute']),
    ];
  }

  /** * {@inheritdoc} */
  public function getFilters() {
    return [
      // Translation filters.       new TwigFilter('t', 't', ['is_safe' => ['html']]),
      new TwigFilter('trans', 't', ['is_safe' => ['html']]),
      // The "raw" filter is not detectable when parsing "trans" tags. To detect       // which prefix must be used for translation (@, !, %), we must clone the       // "raw" filter and give it identifiable names. These filters should only       // be used in "trans" tags.       // @see TwigNodeTrans::compileString()       new TwigFilter('placeholder', [$this, 'escapePlaceholder']['is_safe' => ['html'], 'needs_environment' => TRUE]),

      // Replace twig's escape filter with our own.       new TwigFilter('drupal_escape', [$this, 'escapeFilter']['needs_environment' => TRUE, 'is_safe_callback' => 'twig_escape_filter_is_safe']),

      
Home | Imprint | This part of the site doesn't use cookies.