Menu control

Asked

Viewed 55 times

1

I have a menu in a Bundle and have want to add to that menu a part that is in another menu, but I want those menus to appear both on all pages.

The main menu is this:

{# src/RoqSys/BaseBundle/Resources/views/Default/base.html.twig #}
{% extends '::base.html.twig' %}
<div class="row">
    <div class="col-md-2 column">
        {% block menu %}
            <div class="panel-group" id="accordion">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            Início
                        </h4>
                    </div>
                </div>
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a data-toggle="collapse" data-parent="#accordion" href="#accordionTwo">Configuração</a>
                        </h4>
                    </div>
                    <div id="accordionTwo" class="panel-collapse collapse">
                        <div class="panel-body">
                            <ul>
                                <li><a href="{{ path('gestaoutilizadores') }}">Utilizadores</a></li>
                                <li><a href="{{ path('gestaoparque') }}">Postos</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a data-toggle="collapse" data-parent="#accordion" href="#accordionThree">Encomendas</a>
                        </h4>
                    </div>
                    <div id="accordionThree" class="panel-collapse collapse">
                        <div class="panel-body">
                            <ul>
                                <li><a href="{{ path('registonova') }}">Registo de nova</a></li>
                                <li><a href="{{ path('encomendasabertas') }}">Encomendas em produção</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a data-toggle="collapse" data-parent="#accordion" href="#accordionFour">Produção</a>
                        </h4>
                    </div>
                    <div id="accordionFour" class="panel-collapse collapse">
                        <div class="panel-body">
                            <ul> 
                                <li><a href="{{ path('parqueinstalado') }}">Postos</a></li>
                                <li>Workflow
                                    <ul>
                                        <li><a href="{{ path('registolote') }}">Nova Ordem de Fabrico</a></li>
                                        <li><a href="{{ path('resistooperacao') }}">Registo de Operação</a></li>
                                    </ul>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        {% endblock %}
    </div>
    <div class="col-md-10 column">
    {% block content %}{% endblock %}
</div>

And the other part of the menu is:

{# src/RoqSys/ManutencoaBundle/Resources/views/Default/index.html.twig #}
{% extends 'RoqSysBaseBundle:Default:base.html.twig' %}

{% block menu %}
{{ parent() }}
<div class="panel-group" id="accordiontwo">
    <div class="panel panel-default">
        <div class="panel-heading">
            <h4 class="panel-title">Vista</h4>
        </div>
        <div class="panel-heading">
            <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#accordiontwo" href="#accordionSix">Intervenção</a>
            </h4>
        </div>
        <div id="accordionSix" class="panel-collapse collapse">
            <div class="panel-body">
                <ul>
                    <li><a href="{{ path('manutencao_intervencao') }}">Lista das Intervenções</a></li>
                    <li><a href="{{ path('manutencao_intervencao_new') }}">Nova Intervenção</a></li>
                </ul>
            </div>
        </div>
        <div class="panel-heading">
            <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#accordiontwo" href="#accordionSeven">Previsões</a>
            </h4>
        </div>
        <div id="accordionSeven" class="panel-collapse collapse">
            <div class="panel-body">
                <ul>
                    <li><a href="{{ path('manutencao_prevista') }}">Lista das Previsões</a></li>
                    <li><a href="{{ path('manutencao_prevista_new') }}">Nova Previsão</a></li>
                </ul>
            </div>
        </div>
                <div class="panel-heading">
            <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#accordiontwo" href="#accordionEight">Avarias</a>
            </h4>
        </div>
        <div id="accordionEight" class="panel-collapse collapse">
            <div class="panel-body">
                <ul>
                    <li><a href="{{ path('manutencao_avaria') }}">Lista das Avarias</a></li>
                    <li><a href="{{ path('manutencao_avaria_new') }}">Avaria</a></li>
                </ul>
            </div>
        </div>
        <div class="panel-heading">
            <h4 class="panel-title">Consulta</h4>
        </div>
    </div>
</div>
<div class="col-md-10 column">
    {% block content %}{% endblock %}
</div>
{% endblock %}

Only the second part of the menu only looks like when I put maintenance address bar, and I wanted it to always appear.

I want it to stay that way

inserir a descrição da imagem aqui But it shows up like this inserir a descrição da imagem aqui

1 answer

0

If the file index.html.twig extends the file base.html.twig, just put the block you want in the parent block.

base.html.twig:

{# src/RoqSys/BaseBundle/Resources/views/Default/base.html.twig #}
{% extends '::base.html.twig' %}
<div class="row">
    <div class="col-md-2 column">
        {% block menu %}
            <div class="panel-group" id="accordion">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            Início
                        </h4>
                    </div>
                </div>
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a data-toggle="collapse" data-parent="#accordion" href="#accordionTwo">Configuração</a>
                        </h4>
                    </div>
                    <div id="accordionTwo" class="panel-collapse collapse">
                        <div class="panel-body">
                            <ul>
                                <li><a href="{{ path('gestaoutilizadores') }}">Utilizadores</a></li>
                                <li><a href="{{ path('gestaoparque') }}">Postos</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a data-toggle="collapse" data-parent="#accordion" href="#accordionThree">Encomendas</a>
                        </h4>
                    </div>
                    <div id="accordionThree" class="panel-collapse collapse">
                        <div class="panel-body">
                            <ul>
                                <li><a href="{{ path('registonova') }}">Registo de nova</a></li>
                                <li><a href="{{ path('encomendasabertas') }}">Encomendas em produção</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a data-toggle="collapse" data-parent="#accordion" href="#accordionFour">Produção</a>
                        </h4>
                    </div>
                    <div id="accordionFour" class="panel-collapse collapse">
                        <div class="panel-body">
                            <ul> 
                                <li><a href="{{ path('parqueinstalado') }}">Postos</a></li>
                                <li>Workflow
                                    <ul>
                                        <li><a href="{{ path('registolote') }}">Nova Ordem de Fabrico</a></li>
                                        <li><a href="{{ path('resistooperacao') }}">Registo de Operação</a></li>
                                    </ul>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            <div class="panel-group" id="accordiontwo">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">Vista</h4>
                    </div>
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a data-toggle="collapse" data-parent="#accordiontwo" href="#accordionSix">Intervenção</a>
                        </h4>
                    </div>
                    <div id="accordionSix" class="panel-collapse collapse">
                        <div class="panel-body">
                            <ul>
                                <li><a href="{{ path('manutencao_intervencao') }}">Lista das Intervenções</a></li>
                                <li><a href="{{ path('manutencao_intervencao_new') }}">Nova Intervenção</a></li>
                            </ul>
                        </div>
                    </div>
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a data-toggle="collapse" data-parent="#accordiontwo" href="#accordionSeven">Previsões</a>
                        </h4>
                    </div>
                    <div id="accordionSeven" class="panel-collapse collapse">
                        <div class="panel-body">
                            <ul>
                                <li><a href="{{ path('manutencao_prevista') }}">Lista das Previsões</a></li>
                                <li><a href="{{ path('manutencao_prevista_new') }}">Nova Previsão</a></li>
                            </ul>
                        </div>
                    </div>
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a data-toggle="collapse" data-parent="#accordiontwo" href="#accordionEight">Avarias</a>
                        </h4>
                    </div>
                    <div id="accordionEight" class="panel-collapse collapse">
                        <div class="panel-body">
                            <ul>
                                <li><a href="{{ path('manutencao_avaria') }}">Lista das Avarias</a></li>
                                <li><a href="{{ path('manutencao_avaria_new') }}">Avaria</a></li>
                            </ul>
                        </div>
                    </div>
                    <div class="panel-heading">
                        <h4 class="panel-title">Consulta</h4>
                    </div>
                </div>
            </div>
        {% endblock %}
    </div>
    <div class="col-md-10 column">
        {% block content %}{% endblock %}
    </div>
</div>

index.html.twig:

{# src/RoqSys/ManutencoaBundle/Resources/views/Default/index.html.twig #}
{% extends 'RoqSysBaseBundle:Default:base.html.twig' %}

{% block content %}{% endblock %}
  • but that already has in the fifth line of the base.html already this the menu block.

  • So: just copy the contents of the index.html.Twig menu block to the base.html.Twig menu block. So the menu that appeared on just a few pages now appears on all.

  • the problem is that in Basebunble that menu is being called in several files and Manutencaobundle that menu is also being called in several files, but in the files inside Manutencaobundle and Basebundle only the menu inside Basebundle is being called.

  • This is not necessary. Leave the menu block only in base.html.Twig and delete the block from the other files. So you do not extend the block and it stays as defined in the initial file.

  • what I have in the Maintainer files bundle is already calling the base menu {% extends 'Roqsyscontrolmanutencaobundle:Default:base.html.Twig' %} {% block content -%} calls in the base at the penultimate line

  • How’s your Twig file hierarchy? And what problem are you currently having?

  • Basically I want the two menus to be together in one and to appear in all my files of the two.

  • Rodrigo Rogotti see the images above.

  • I made a correction in the code because the block content appeared twice and was inside the block menu. The solution I proposed solves your problem: just leave the block menu only in base.html.twig (actually you don’t even need to declare the block menu, if it will not be extended in the other files) and not declare it in the other files.

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.