Documentation

AsTwigFilter
in package

FinalYes

Registers a method as template filter.

If the first argument of the method has Twig\Environment type-hint, the filter will receive the current environment. Additional arguments of the method come from the filter call.

#[AsTwigFilter(name: 'foo')]
function fooFilter(Environment $env, $string, $arg1 = null, ...) { ... }

{{ 'string'|foo(arg1) }}

Tags
see
TwigFilter
Attributes
#[Attribute]
\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE

Table of Contents

Properties

$deprecationInfo  : DeprecatedCallableInfo|null
$isSafe  : array<string|int, mixed>|null
$isSafeCallback  : string|array<string|int, mixed>|null
$name  : string
$needsCharset  : bool|null
$needsContext  : bool|null
$needsEnvironment  : bool|null
$preEscape  : string|null
$preservesSafety  : array<string|int, mixed>|null

Methods

__construct()  : mixed

Properties

$isSafe

public array<string|int, mixed>|null $isSafe = null

$isSafeCallback

public string|array<string|int, mixed>|null $isSafeCallback = null

$needsEnvironment

public bool|null $needsEnvironment = null

$preservesSafety

public array<string|int, mixed>|null $preservesSafety = null

Methods

__construct()

public __construct(non-empty-string $name[, bool|null $needsCharset = null ][, bool|null $needsEnvironment = null ][, bool|null $needsContext = null ][, array<string|int, string>|null $isSafe = null ][, string|array<string|int, mixed>|null $isSafeCallback = null ][, string|null $preEscape = null ][, array<string|int, string>|null $preservesSafety = null ][, DeprecatedCallableInfo|null $deprecationInfo = null ]) : mixed
Parameters
$name : non-empty-string

The name of the filter in Twig

$needsCharset : bool|null = null

Whether the filter needs the charset passed as the first argument

$needsEnvironment : bool|null = null

Whether the filter needs the environment passed as the first argument, or after the charset

$needsContext : bool|null = null

Whether the filter needs the context array passed as the first argument, or after the charset and the environment

$isSafe : array<string|int, string>|null = null

List of formats in which you want the raw output to be printed unescaped

$isSafeCallback : string|array<string|int, mixed>|null = null

Function called at compilation time to determine if the filter is safe

$preEscape : string|null = null

Some filters may need to work on input that is already escaped or safe

$preservesSafety : array<string|int, string>|null = null

Preserves the safety of the value that the filter is applied to

$deprecationInfo : DeprecatedCallableInfo|null = null

Information about the deprecation


        
On this page

Search results