+ # Generate navigation links for the trail of this article, if any.
+ #
+ # A trail is generated if the article include or is included in a trail.
+ # See `wiki.trails` for details.
+ fun tpl_trail: Writable do
+ if not wiki.trails.has(self) then return ""
+
+ # Get the position of `self` in the trail
+ var flat = wiki.trails.to_a
+ var pos = flat.index_of(self)
+ assert pos >= 0
+
+ var res = new Template
+ res.add "<ul class=\"trail\">"
+ var parent = wiki.trails.parent(self)
+ # Up and prev are disabled on a root
+ if parent != null then
+ if pos > 0 then
+ var target = flat[pos-1]
+ res.add "<li>{target.a_from(self, "prev")}</li>"
+ end
+ res.add "<li>{parent.a_from(self, "up")}</li>"
+ end
+ if pos < flat.length - 1 then
+ var target = flat[pos+1]
+ # Only print the next if it is not a root
+ if target.parent != null then
+ res.add "<li>{target.a_from(self, "next")}</li>"
+ end
+ end
+ res.add "</ul>"
+
+ return res
+ end
+