Skip to content

Commit c848bc0

Browse files
committed
Add aria-current attribute menu builder recipe
1 parent ac43ad5 commit c848bc0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

content/docs/2_cookbook/3_templating/0_menu-builder/cookbook-recipe.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ In the template:
3434
<nav>
3535
<ul>
3636
<?php foreach ($menu as $menuItem) : ?>
37-
<li><a href="<?= $menuItem->url() ?>"><?= $menuItem->title() ?></a></li>
37+
<li><a <?php e($menuItem->isOpen(), 'aria-current="page"') ?> href="<?= $menuItem->url() ?>"><?= $menuItem->title() ?></a></li>
3838
<?php endforeach ?>
3939
</ul>
4040
</nav>
@@ -72,7 +72,7 @@ In the template, we can use it like this to render each menu with its headline:
7272
<h4><?= $menu->menuHeadline()->html() ?></h4>
7373
<ul>
7474
<?php foreach ($menuItems as $menuItem) : ?>
75-
<li><a href="<?= $menuItem->url() ?>"><?= $menuItem->title() ?></a></li>
75+
<li><a <?php e($menuItem->isOpen(), 'aria-current="page"') ?> href="<?= $menuItem->url() ?>"><?= $menuItem->title() ?></a></li>
7676
<?php endforeach ?>
7777
</ul>
7878
</nav>
@@ -112,7 +112,7 @@ In the template:
112112
<nav>
113113
<ul>
114114
<?php foreach ($menuItems as $menuItem) : ?>
115-
<li><a href="<?= $menuItem->link()->toUrl() ?>"><?= $menuItem->linkTitle()->or($menuItem->link()->html()) ?></a></li>
115+
<li><a <?= ($p = $menuItem->link()->toPage()) && $p->isOpen() ? 'aria-current="page"' : '' ?> href="<?= $menuItem->link()->toUrl() ?>"><?= $menuItem->linkTitle()->or($menuItem->link()->html()) ?></a></li>
116116
<?php endforeach ?>
117117
</ul>
118118
</nav>
@@ -157,7 +157,7 @@ if ($menu->isNotEmpty()) : ?>
157157
<ul>
158158
<?php foreach ($menu as $item): ?>
159159
<?php if ($mainMenuItem = $item->mainMenu()->toPage()) : ?>
160-
<li><a href="<?= $mainMenuItem->url() ?>"><?= $mainMenuItem->title() ?></a>
160+
<li><a <?php e($mainMenuItem->isOpen(), 'aria-current="page"') ?> href="<?= $mainMenuItem->url() ?>"><?= $mainMenuItem->title() ?></a>
161161
<?php endif ?>
162162
<?php $subMenu = $item->subMenu()->toPages(); ?>
163163
<?php if ($item->hasSubmenu()->isTrue() && $subMenu->isNotEmpty()) : ?>

0 commit comments

Comments
 (0)