summaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorSepts <github@septs.pw>2022-11-30 12:02:57 +0800
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-12-23 10:14:53 +0100
commit3a216186b2cfa479c250dabb64eff022a388fb40 (patch)
tree77ebcc25658f473b6c9b077593ab572974fae946 /docs
parent7874b96815abf1e10b2947d9b3804767108ec939 (diff)
resource/page: Add Page.Ancestors
Fixes #10567
Diffstat (limited to 'docs')
-rw-r--r--docs/content/en/content-management/sections.md21
-rw-r--r--docs/content/en/variables/page.md3
2 files changed, 12 insertions, 12 deletions
diff --git a/docs/content/en/content-management/sections.md b/docs/content/en/content-management/sections.md
index 5ff884610..b68a5bdb9 100644
--- a/docs/content/en/content-management/sections.md
+++ b/docs/content/en/content-management/sections.md
@@ -63,19 +63,16 @@ If you need a specific template for a sub-section, you need to adjust either the
With the available [section variables and methods](#section-page-variables-and-methods) you can build powerful navigation. One common example would be a partial to show Breadcrumb navigation:
{{< code file="layouts/partials/breadcrumb.html" download="breadcrumb.html" >}}
-<ol class="nav navbar-nav">
- {{ template "breadcrumbnav" (dict "p1" . "p2" .) }}
-</ol>
-{{ define "breadcrumbnav" }}
-{{ if .p1.Parent }}
-{{ template "breadcrumbnav" (dict "p1" .p1.Parent "p2" .p2 ) }}
-{{ else if not .p1.IsHome }}
-{{ template "breadcrumbnav" (dict "p1" .p1.Site.Home "p2" .p2 ) }}
-{{ end }}
-<li{{ if eq .p1 .p2 }} class="active" aria-current="page" {{ end }}>
- <a href="{{ .p1.Permalink }}">{{ .p1.Title }}</a>
+<ol class="nav navbar-nav">
+<ul>
+{{- range .Ancestors.Reverse }}
+<li><a href="{{ .Permalink }}">{{ .Title }}</a></li>
+{{- end }}
+<li class="active" aria-current="page">
+<a href="{{ .Permalink }}">{{ .Title }}</a>
</li>
-{{ end }}
+</ul>
+</ol>
{{< /code >}}
## Section Page Variables and Methods
diff --git a/docs/content/en/variables/page.md b/docs/content/en/variables/page.md
index 07acc4831..2de54ff8b 100644
--- a/docs/content/en/variables/page.md
+++ b/docs/content/en/variables/page.md
@@ -32,6 +32,9 @@ See [`.Scratch`](/functions/scratch/) for page-scoped, writable variables.
.Aliases
: aliases of this page
+.Ancestors
+: get the ancestors of each page, simplify [breadcrumb navigation]({{< relref "content-management/sections#example-breadcrumb-navigation" >}}) implementation complexity
+
.BundleType
: the [bundle] type: `leaf`, `branch`, or an empty string if the page is not a bundle.