A
A
andreyqin2014-01-29 20:37:15
Twig
andreyqin, 2014-01-29 20:37:15

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);
}

I have an array that I just need to pass to the base template in order to use it in the child templates. How can I do this without loading the base template itself? That is, just transfer the data and that's it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Gusakov, 2014-01-30
@hell0w0rd

what?
your function does a bunch of actions that should be done separately

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question