Reputation: 3356
I am a Symfony beginner my approach might not be the right way to do things so please help me what am i doing wrong. In my base.html.twig
i am including a 'menu template' {% include'::menu.html.twig' %}
This holds all the default top menu items which is working fine.
Now what i am trying to do is on a about
page I need additional menu option called 'Extra', it does appear but not as a part of a menu. I thought if you call parent()
this should work just like when you are trying to add extra css or js files using parent
This is what my about.html.twig
looks like
{% extends "::base.html.twig" %}
{% block topmenu %}
{{ parent() }}
<li><a href="">Extra</a></li>
{% endblock %}
{% block body %}
This is body
{% endblock %}
And this is what I see in browser, the menu option Extra needs to be the part of rest of the menu
I will really appreciate any assistance here.
This is what my menu.html.twig
looks like
{% block topmenu %}
<header class="navbar navbar-inverse navbar-fixed-top wet-asphalt" role="banner">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html"><img src="" alt="logo"></a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="">Home</a></li>
<li><a href="">About Us</a></li>
<li><a href="">Services</a></li>
<li><a href="">Portfolio</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Pages <i class="icon-angle-down"></i></a>
</li>
<li><a href="">Blog</a></li>
<li><a href="">Contact</a></li>
</ul>
</div>
</div>
</header>
{% endblock %}
Upvotes: 0
Views: 1288
Reputation: 45
Instead of trying to add an extra line to your template on specific routes, you should make a condition on that route to display this extra menu :
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="">Home</a></li>
<li><a href="">About Us</a></li>
<li><a href="">Services</a></li>
<li><a href="">Portfolio</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Pages <i class="icon-angle-down"></i></a>
</li>
<li><a href="">Blog</a></li>
<li><a href="">Contact</a></li>
{% if app.request.attributes.get('_route') == 'my_route' %}
<li><a href="">Extra</a></li>
{% endif %}
</ul>
</div>
Upvotes: 0