Skip to content

Commit

Permalink
Merge pull request #17 from loic425/fix/active-menu
Browse files Browse the repository at this point in the history
Fix active menu detection
  • Loading branch information
loic425 authored Sep 29, 2020
2 parents fc246e7 + 42f4432 commit 3c0c7e6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Resources/views/layout/menu.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

<ul class="nav flex-column">
{% for item in menu_items %}
{{ menu.nav_item(page_title(item.slug), item.path, current_item) }}
{{ menu.nav_item(item.slug, item.path, current_item) }}
{% endfor %}
</ul>
2 changes: 1 addition & 1 deletion src/Resources/views/layout/sidebar_menu.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% import '@MobizelMarkdownDocs/macro/menu.html.twig' as menu %}

<ul class="nav flex-column">
{{ render(path('mobizel_markdown_docs_menu', {'current_item': app.request.requestUri})) }}
{{ render(path('mobizel_markdown_docs_menu', {'current_item': app.request.get('slug')})) }}
</ul>
7 changes: 4 additions & 3 deletions src/Resources/views/macro/menu.html.twig
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{% macro nav_item(title, path, current_item) %}
{% set current = (path in current_item) %}
{% macro nav_item(slug, path, current_item) %}
{% set root = current_item|split('/')|first %}
{% set current = (slug == root) %}
<li class="nav-item">
<a class="nav-link {% if current %}active{% endif %}" href="{{ path }}">
{{ title }} {% if current %}<span class="sr-only">(current)</span>{% endif %}
{{ page_title(slug) }} {% if current %}<span class="sr-only">(current)</span>{% endif %}
</a>
</li>
{% endmacro %}

0 comments on commit 3c0c7e6

Please sign in to comment.