Skip to content

Commit b42dac6

Browse files
authored
Merge pull request #383 from torchbox/fix/navigation-tags-500
Fix: Check first if the page exists in the context
2 parents 5165322 + df11cef commit b42dac6

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

tbx/navigation/templatetags/navigation_tags.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ def primarynavmobile(context):
3434

3535
@register.simple_tag(name="get_top_level_parent_page", takes_context=True)
3636
def get_top_level_parent_page(context):
37+
# Exit immediately if there is there's no data available.
38+
if "page" not in context or "settings" not in context:
39+
return None
40+
3741
# Get all page links from the primary nav.
3842
primary_nav = [
3943
block.value["page"]

tbx/project_styleguide/templates/patterns/organisms/header/header.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,16 @@
2020
</nav>
2121

2222
{# Primary mobile menu toggle #}
23-
<button class="header__primary-menu-toggle" data-primary-mobile-menu-toggle aria-haspopup="true" aria-expanded="false" aria-label="Mobile menu toggle">
24-
Home
23+
{% get_top_level_parent_page as parent_page %} {# Get the top-level parent page #}
24+
{% firstof parent_page.title "Home" as parent_title %} {# Get the parent's title, or Home if no parent #}
25+
<button
26+
aria-expanded="false"
27+
aria-haspopup="true"
28+
aria-label="Mobile menu toggle - currently viewing '{{ parent_title }}' or pages below it"
29+
class="header__primary-menu-toggle"
30+
data-primary-mobile-menu-toggle
31+
>
32+
{{ parent_title }}
2533
{% include "patterns/atoms/icons/icon.html" with name="chevron" classname="header__primary-menu-toggle-icon" %}
2634
</button>
2735

0 commit comments

Comments
 (0)