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
c.Assert(err, qt.IsNil)
c.Assert(active, qt.Equals, true)
c.Assert(p.FirstSection(), qt.Equals, p)
+ c.Assert(len(p.Ancestors()), qt.Equals, 1)
}},
{"l1", func(c *qt.C, p page.Page) {
c.Assert(p.Title(), qt.Equals, "L1s")
c.Assert(len(p.Pages()), qt.Equals, 4) // 2 pages + 2 sections
c.Assert(p.Parent().IsHome(), qt.Equals, true)
c.Assert(len(p.Sections()), qt.Equals, 2)
+ c.Assert(len(p.Ancestors()), qt.Equals, 1)
}},
{"l1,l2", func(c *qt.C, p page.Page) {
c.Assert(p.Title(), qt.Equals, "T2_-1")
c.Assert(p.Parent().Title(), qt.Equals, "L1s")
c.Assert(p.RelPermalink(), qt.Equals, "/l1/l2/")
c.Assert(len(p.Sections()), qt.Equals, 1)
+ c.Assert(len(p.Ancestors()), qt.Equals, 2)
for _, child := range p.Pages() {
if child.IsSection() {
c.Assert(p.Pages()[0].File().Path(), qt.Equals, filepath.FromSlash("l1/l2_2/page_2_2_1.md"))
c.Assert(p.Parent().Title(), qt.Equals, "L1s")
c.Assert(len(p.Sections()), qt.Equals, 0)
+ c.Assert(len(p.Ancestors()), qt.Equals, 2)
}},
{"l1,l2,l3", func(c *qt.C, p page.Page) {
nilp, _ := p.GetPage("this/does/not/exist")
c.Assert(len(p.Pages()), qt.Equals, 2)
c.Assert(p.Parent().Title(), qt.Equals, "T2_-1")
c.Assert(len(p.Sections()), qt.Equals, 0)
+ c.Assert(len(p.Ancestors()), qt.Equals, 3)
l1 := getPage(p, "/l1")
isDescendant, err := l1.IsDescendant(p)
}
c.Assert(home, qt.Not(qt.IsNil))
+ c.Assert(len(home.Ancestors()), qt.Equals, 0)
c.Assert(len(home.Sections()), qt.Equals, 9)
c.Assert(s.Info.Sections(), deepEqualsPages, home.Sections())