The most common way to create any navigation in Tridion is to simply generate it in a C # template based on structural groups and pages.
For example, a trace with roots can be easily generated from a template (either a C # fragment or a class that implements ITemplate
), for example:
var pageDocument = package.GetByType(ContentType.Page).GetAsXmlDocument(); var current = new Page(pageDocument.DocumentElement, engine.GetSession()); var breadcrumb = page.Title; while (current.OrganizationalItem != null) { current = current.OrganizationalItem; breadcrumb = current.Title + " > " + breadcrumb; } package.PushItem("breadcrumb", package.CreateStringItem(ContentType.Text, breadcrumb));
The above fragment really only shows how to move up the hierarchy of structural groups. You still have to make each structure group a link, perhaps looking at the PublishUrl
property of each StructureGroup
.
I know that you did not ask about the sidewalk, your look is more like a left one. But the approach for all navigation elements is similar: go to the corresponding pages and StructureGroups using TOM.NET in your ITemplate and create your HTML code for navigation.
To get a list of all the pages in the current StructureGroup (and mark the current one), I would expect something like this:
var pageDocument = package.GetByType(ContentType.Page).GetAsXmlDocument(); var current = new Page(pageDocument.DocumentElement, engine.GetSession()); var sg = (StructureGroup) page.OrganizationalItem; string result = "<ul>"; foreach (var page in sg.GetItems()) { result += (page.Id != current.Id) ? "<li>" : "<li class='selected'>"; result += page.Title; result += "</li>"; } result += "</ul>"; package.PushItem("siblings", package.CreateHtmlItem(result));
Also see this great example from Nick, where he generates an entire sitemap . This is closer to what you need at the end, but of course there is a lot more code (too much to play here). Albert also shared some of his experiences with this approach and mentions alternatives .
source share