Hello.
Recently I started learning Twig, and I don’t understand how to work with child templates (layouts) at all.
How do I send data to a child layout so that after the output of the main layout, the children are displayed with the transferred data. Or is it necessary to build all layouts with data piece by piece and then collect?
Well, here's how, for example, to transfer the menu array to the menu.twig layout :
index.php
/*...CODE...*/ Twig_Autoloader::register(); $loader = new Twig_Loader_Filesystem($twig_filesystem); $twig = new Twig_Environment($loader, array( 'cache' => TWIG_CACHE, 'debug' => TWIG_DEBUG));
$twig->display('main.twig', array()); /*...CODE...*/ main.twig
/*...CODE...*/ {% include "header.twig" %} /*...CODE...*/ header.twig
/*...CODE...*/ {% include "menu.twig" %} /*...CODE...*/ menu.twig
/*...CODE...*/ {% for link in menu %} <li><a href="{{link.href}}">{{ link.name }}</a></li> {% endfor %} /*...CODE...*/
Help me please. Thank you in advance!
UPD: at least give links, please)