I'm coding an app in PHP for school work and I'm using Twig template engine lonely (without a framework).
I got a file which initialize Twig in my project and I use it in all files that need it.
include_once('./Twig/lib/Twig/Autoloader.php');
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem('./templates');
$twig = new Twig_Environment($loader, array(
'cache' => false,
'charset' => 'utf-8'
));
I have a Twig Function which returns the path to my static files folder. But when I run addFunction($my_function)
I got the error below :
Warning: Missing argument 1 for {closure}()
My Twig function:
$url_for_static = new Twig_SimpleFunction('static_folder', function () {
$static_folder = "./static" ;
return $static_folder ;
});
$twig->addFunction($url_for_static);
I know this answer is really late but i finally found a solution to my problem. My Twig function declaration was wrong. This worked for me :
`
function blank_space($size=100) {
echo "<div class='grid-". $size ." hidden'> <span> hidden </span> </div>" ;
}
$twig->addFunction('blank_space', new Twig_Function_Function('blank_space')) ;
`
I have never used Twig before, but it seems the closure is called with an argument but you didn't define any arguments in your closure. Try this:
$url_for_static = new Twig_SimpleFunction('static_folder', function ($arg) {
var_dump($arg);
$static_folder = "./static" ;
return $static_folder ;
});
I know this answer is really late but i finally found a solution to my problem. My Twig function declaration was wrong.
This worked for me :
function blank_space($size=100) {
echo "<div class='grid-". $size ." hidden'> <span> hidden </span> </div>" ;
}
$twig->addFunction('blank_space', new Twig_Function_Function('blank_space')) ;