mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-12 22:38:52 +00:00
[ticket/16885] Add type casting filters to Twig
PHPBB3-16885
This commit is contained in:
parent
59cece1a0a
commit
ea36b83ee9
1 changed files with 24 additions and 0 deletions
|
@ -79,6 +79,8 @@ class extension extends \Twig\Extension\AbstractExtension
|
||||||
new \Twig\TwigFilter('subset', array($this, 'loop_subset'), array('needs_environment' => true)),
|
new \Twig\TwigFilter('subset', array($this, 'loop_subset'), array('needs_environment' => true)),
|
||||||
// @deprecated 3.2.0 Uses twig's JS escape method instead of addslashes
|
// @deprecated 3.2.0 Uses twig's JS escape method instead of addslashes
|
||||||
new \Twig\TwigFilter('addslashes', 'addslashes'),
|
new \Twig\TwigFilter('addslashes', 'addslashes'),
|
||||||
|
new \Twig\TwigFilter('int', [$this, 'type_int']),
|
||||||
|
new \Twig\TwigFilter('float', [$this, 'type_float']),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,6 +167,28 @@ class extension extends \Twig\Extension\AbstractExtension
|
||||||
return twig_slice($env, $item, $start, $end, $preserveKeys);
|
return twig_slice($env, $item, $start, $end, $preserveKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cast to INT a variable
|
||||||
|
*
|
||||||
|
* Example: config('my_awesome_config')|int
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function type_int($value)
|
||||||
|
{
|
||||||
|
return (int) $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cast to FLOAT a variable
|
||||||
|
*
|
||||||
|
* Example: config('my_awesome_config')|float
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
public function type_float($value)
|
||||||
|
{
|
||||||
|
return (float) $value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get output for a language variable (L_FOO, LA_FOO)
|
* Get output for a language variable (L_FOO, LA_FOO)
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue