Question

I have created different pages for all these categories: books, mobiles, comp, etc. Now I want to put this type of navigation menu (as shown in figure) in all pages and opening a page should highlight the corresponding menu link.

Should I create a schema which contains text and a link and make it multivalued? So then I create a component and finally render them in all pages?

If not please suggest any other better approach to do so.

enter image description here

Was it helpful?

Solution

If you use ASPX as page types, below is described other logic for navigation:

  1. Create one navigation xml (contains all pages) with important pages info (ID, path, title...)

  2. Create ascx control that will generate breadcrumb or any other navigation. As parameter control should retrieve current page ID

  3. Change page DWT (placing ascx control)

On this way you decrease rendering (publishing) time, navigation will be rendered on page loading. Unfortunately you increase page loading time by this way. It depends on your need what is more appropriate solution for you. Refreshing navigation XML is one of the problem of this approach....

OTHER TIPS

The most common way to generate any navigation in Tridion is to simply generate it in a C# template based on the Structure Groups and Pages.

For example a breadcrumb trail can be easily generated from within a template (either a C# fragment or a class implementing ITemplate) by something like this:

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 navigate the hierarchy of structure groups upwards. You'll still have to make every structure group as a link, probably by looking at PublishUrl property of every StructureGroup.

I know you were not asking about a breadcrumb trail, yours looks more like a leftnav. But the approach for all navigation elements is similar: traverse the relevant Pages and StructureGroups using the TOM.NET in your ITemplate and generate your navigation HTML from that.

To get a list of all the Pages in the current StructureGroup (and mark the current one), I'd 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));

Please also see this great example from Nick where he generates an entire sitemap. That is closer to what you'll need in the end, but is of course a lot more code (too much to reproduce here). Albert also shared some of his experience with this approach and mentions the alternatives.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top