A
A
Alex_ART2017-07-11 13:11:29
symfony
Alex_ART, 2017-07-11 13:11:29

How to make 1 insert for all templates in Twig?

Trying to figure out with Twig
;
Let's say base.html has {% block menu %}{% endblock %}
Take the index.html template which is {% extends "base.html" %}
This is where we pass $rsCategories to the index.html template

function indexAction($twig){
 $rsCategories =  getAllCatsWithChildren();
 $template = loadTemplate($twig, 'index.html');
echo $template->render(array(
     'rsCategories' => $rsCategories));}

Then in index.html I do a loop
{% block menu %}
{% for categorie in rsCategories %} < вывод категорий> {% endfor %}
{% endblock %}

And I get category output in index.html
How can I get the same output on other pages?
I mean, it's clear that you can include or use {{ parent() }}
But we passed $rsCategories only to index.html, i.e. in index_2.html and other templates, the loop will not work because. not passed $rsCategories
Pass in every function for every template
$rsCategories =  getAllCatsWithChildren(); 
rsCategories' => $rsCategories

???)
It works, but there should be a more profitable solution, tell me, thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BoShurik, 2017-07-11
@Alex_ART

Analogue of 1C-Bitrix components in Symfony?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question