How to create navigation menus for different pages in SDL Tridion?

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

Should I create a schema containing text and a link and make it ambiguous? So, I create a component and finally do them on all pages?

If not, suggest another best approach for this.

enter image description here

+6
source share
2 answers

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

  • Create one navigation xml (contains all pages) with important page information (ID, path, title ...)

  • Create an ascx control that will generate a bulletin board or any other navigation. Since parameter management should retrieve the current page id

  • Change DWT page (ascx management placement)

Thus, you reduce the time of rendering (publication), navigation will be displayed when the page loads. Unfortunately, this way you increase the page load time. It depends on your need, which is the more suitable solution for you. Updating XML navigation is one of the challenges of this approach ....

+5
source

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 .

+9
source

Source: https://habr.com/ru/post/916735/


All Articles