H
H
haa2016-06-12 22:46:41
OOP
haa, 2016-06-12 22:46:41

How to use Twig correctly?

Good evening! I am creating a not very big project, I decided to use OOP and twig. Only in order for the Front end and Back end to lie separately. The structure of the site is very simple, there is a left sidebar (dynamic) where the menu is displayed and the main content where the text is also dynamic. To display content, I created the articles class, which outputs articles.tpl to its template, and for the menu, the menu class, which outputs to the menu.tpl template, and this template is connected

<section class="content">
    <div class="container">
      <div class="row">
        {% include "menu.tpl" %}
        {% block content %} 
            {#тут контент#}
        {% endblock %}
      </div>	
    </div>	
  </section>

And through render I draw a conclusion.
//Объект для вывода меню
$menu_object = new menu;	
$menu=$menu_object->view()
echo $template->render(array('title'=>'Мой сайт', 'articles'=>$articles, 'menu_pages'=>$menu));

And the question is, inside the articles class, create an object (s) to display the menu and send it to the output, is this normal? If not, how can it be deduced so that there is no duplication of code.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question