AsTwigFunction
in package
FinalYes
Registers a method as template function.
If the first argument of the method has Twig\Environment type-hint, the function will receive the current environment. Additional arguments of the method come from the function call.
#[AsTwigFunction(name: 'foo')]
function fooFunction(Environment $env, string $string, $arg1 = null, ...) { ... }
{{ foo('string', arg1) }}
Tags
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
Methods
- __construct() : mixed
Properties
$deprecationInfo
public
DeprecatedCallableInfo|null
$deprecationInfo
= null
$isSafe
public
array<string|int, mixed>|null
$isSafe
= null
$isSafeCallback
public
string|array<string|int, mixed>|null
$isSafeCallback
= null
$name
public
string
$name
$needsCharset
public
bool|null
$needsCharset
= null
$needsContext
public
bool|null
$needsContext
= null
$needsEnvironment
public
bool|null
$needsEnvironment
= 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 ][, DeprecatedCallableInfo|null $deprecationInfo = null ]) : mixed
Parameters
- $name : non-empty-string
-
The name of the function in Twig
- $needsCharset : bool|null = null
-
Whether the function needs the charset passed as the first argument
- $needsEnvironment : bool|null = null
-
Whether the function needs the environment passed as the first argument, or after the charset
- $needsContext : bool|null = null
-
Whether the function 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 function is safe
- $deprecationInfo : DeprecatedCallableInfo|null = null
-
Information about the deprecation