Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

UL tag extra in navigation menu

Started by Pedro M 6 years ago · 0 replies · 461 views
6 years ago

Hi.

I have this code in the navigation.html.twig:

TWIG
{% macro nav_loop(page) %}
{% import _self as macros %}

  {% for p in page.children.visible %}
    {% set active_page = (p.active or p.activeChild) ? 'active' : '' %}
    <li class="scroll {{active_page}}"><a href="{{ p.url }}">{{ p.menu }}</a></li>
  {% endfor %}

{% endmacro %}

If you can see the result with the Chrome Inspector, you can check that the code has changed to (for example):

HTML
<ul class="navigation">
<li><a class="" href="#services">services</a></li>
<li><a class="" href="#about-us">about-us</a></li>
</ul>

First: my classes in li tag have dissapeared (scroll, active).
Second: Grav adds and extra ul tag.

All of this makes that I can' take control of my classes, for example, in one theme that contain a line with \<ul class="nav navbar-nav navbar-right"> and then differents lines with \<li class="whatever">, the end result will be:

HTML
<ul class="nav navbar-nav navbar-right">
<ul class="navigation">
<li>whatever</li>
<li>whatever</li>
</ul>
</ul>

Is there any way to make a navigation.html.twig file that respects the css classes?

Thanks in advance.

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 104 18 hours ago
General · by pamtbaau, 23 hours ago
1 88 22 hours ago
General · by Andy Miller, 1 day ago
0 53 1 day ago
General · by Marcel, 12 months ago
6 381 5 days ago
General · by Duc , 6 days ago
3 69 6 days ago