Answer the question
In order to leave comments, you need to log in
How to easily pass data to a template using Twig
I have a function with which I load the template I need and pass data to it if necessary:
function templateLoader($page, $data = array())
{
require_once 'templates/Twig/Autoloader.php';
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem('templates');
$twig = new Twig_Environment($loader);
echo $twig->render($page . '.html', $data);
}
Answer the question
In order to leave comments, you need to log in
what?
your function does a bunch of actions that should be done separately
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question