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

Bootstrap Drop Down

Started by Muut Archive 11 years ago · 2 replies · 309 views
11 years ago

Hi,

I am having trouble with getting Grav's menu system to work with Bootstrap's Nav Dropdown.

Any suggestions?

Thanks in advanced

11 years ago

Thanks to the power of the Internet, I've manged to find a solution.
For those that need it in the future, add the following between your unordered list tags.
__
{% for page in pages.children.visible %}
{% set current_page = (page.active or page.activeChild) ? 'active' : '' %}
{% if page.children.visible.count > 0 %}
<li class="dropdown {{ current_page }}">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{{ page.menu }} <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
{% set current_parent = page.active ? 'active' : '' %}
<li class="{{ current_parent }}"><a href="{{ page.url }}">{{ page.menu }}</a></li>
<li class="divider"></li>
{% for child in page.children.visible %}
{% set current_child = (child.active or child.activeChil d) ? 'active' : '' %}
<li class="{{ current_child }}"><a href="{{ child.url }}">{{ child.menu }}</a></li>
{% endfor %}
</ul>
</li>
{% else %}
<li class="{{ current_page }}"><a href="{{ page.url }}">{{ page.menu }}</a></li>
{% endif %}
{% endfor %}
__

11 years ago

I think the Bootstrap plugin already has support for enabling dropdowns. It should be a theme configuration setting.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1336 9 years ago
Archive · by Muut Archive, 9 years ago
2 925 9 years ago
Archive · by Muut Archive, 9 years ago
2 4056 9 years ago
Archive · by Muut Archive, 9 years ago
1 2941 9 years ago
Archive · by Muut Archive, 9 years ago
3 1112 9 years ago