Created
November 21, 2013 10:30
-
-
Save apfelbox/7579366 to your computer and use it in GitHub Desktop.
varargs in Twig custom functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Extension extends Twig_Extension | |
{ | |
public function myFunc () | |
{ | |
var_dump(func_get_args()); | |
} | |
public function getFunctions () | |
{ | |
return [ | |
new Twig_SimpleFunction("myFunc", [$this, "myFunc"]) | |
]; | |
} | |
public function getName () | |
{ | |
"test"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'vendor/autoload.php'; | |
require_once 'Extension.php'; | |
$loader = new Twig_Loader_String(); | |
$twig = new Twig_Environment($loader, [ | |
]); | |
$twig->addExtension(new Extension()); | |
echo $twig->render("{{ myFunc(1, 2, 3, 4, 5) }}"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: