Skip to content

Commit

Permalink
added condition to include nav item only if url is not empty (#1449)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
umar8hassan authored Nov 11, 2024
1 parent 1e1c759 commit 71b4557
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
13 changes: 9 additions & 4 deletions course-v2/layouts/partials/nav_item.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

<li class="course-nav-list-item">
<div class="course-nav-parent d-flex flex-direction-row align-items-center justify-content-between">
Expand All @@ -17,15 +22,15 @@
)
)
-}}
{{ else }}
{{ else if or $url $hasOneValidChild }}
<a class="text-dark nav-link"
data-uuid="{{ .menuItem.Identifier }}"
href="{{ $url }}">
{{ if $url }} href="{{ $url }}" {{ else }} href="#" {{ end }}>
{{ .menuItem.Name }}
</a>
{{ end }}
</span>
{{ if .menuItem.HasChildren }}
{{ if $hasOneValidChild }}
<button
class="course-nav-section-toggle"
type="button"
Expand All @@ -41,7 +46,7 @@
</button>
{{ end }}
</div>
{{ if or (not $hasParent) $hasChildren }}
{{ if or (and (not $hasParent) $url) $hasOneValidChild }}
<span class="medium-and-below-only"><hr/></span>
{{ end }}
<ul
Expand Down
19 changes: 19 additions & 0 deletions course-v2/layouts/partials/nav_item_has_child.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{ $hasOneValidChild := false }}

{{ range . }}
{{ $url := partial "nav_url.html" (dict "menuItem" .) }}

{{ if .HasChildren }}
{{ $hasOneValidChild = partial "nav_item_has_child.html" .Children }}
{{ if $hasOneValidChild }}
{{ break }}
{{ end }}
{{ else }}
{{ if $url }}
{{ $hasOneValidChild = true }}
{{ break }}
{{ end }}
{{ end }}
{{ end }}

{{ return $hasOneValidChild }}

0 comments on commit 71b4557

Please sign in to comment.