From 71b4557d3cbacd4b74ea59863b5e81c0579b65b2 Mon Sep 17 00:00:00 2001 From: Umar Hassan Date: Mon, 11 Nov 2024 18:53:09 +0500 Subject: [PATCH] added condition to include nav item only if url is not empty (#1449) * added condition to include nav item only if url is not empty * added conditional rendering of parent only if atleast has one child with url * added missing partial file * added nested checking for valid children * fixed false active tag and fixed span condition --- course-v2/layouts/partials/nav_item.html | 13 +++++++++---- .../layouts/partials/nav_item_has_child.html | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 course-v2/layouts/partials/nav_item_has_child.html diff --git a/course-v2/layouts/partials/nav_item.html b/course-v2/layouts/partials/nav_item.html index 3a0f2848f..37c2ba381 100644 --- a/course-v2/layouts/partials/nav_item.html +++ b/course-v2/layouts/partials/nav_item.html @@ -4,6 +4,11 @@ {{ $hasChildren := .menuItem.HasChildren }} {{ $url := partial "nav_url.html" . }} {{ $linkedPage := site.GetPage .menuItem.PageRef }} +{{ $hasOneValidChild := false }} + +{{ if $hasChildren }} + {{ $hasOneValidChild = partial "nav_item_has_child.html" .menuItem.Children }} +{{ end }}
  • @@ -17,15 +22,15 @@ ) ) -}} - {{ else }} + {{ else if or $url $hasOneValidChild }} + {{ if $url }} href="{{ $url }}" {{ else }} href="#" {{ end }}> {{ .menuItem.Name }} {{ end }} - {{ if .menuItem.HasChildren }} + {{ if $hasOneValidChild }}
    - {{ if or (not $hasParent) $hasChildren }} + {{ if or (and (not $hasParent) $url) $hasOneValidChild }}
    {{ end }}