The easiest way to achieve this is to:
- Create a page type called External Link
- Add a few fields to it for Name, DisplayText, LinkURL
- In your Repo for navigation make sure you use
pageRetriever.RetrieveMultiple()
like so.
var items = pageRetriever.RetrieveMultiple(
query => query
.Path(path, PathTypeEnum.Section)
.InCategories(categoryName)
.WithCoupledColumns()
.OrderBy(nameof(TreeNode.NodeLevel), nameof(TreeNode.NodeOrder)),
cache => cache
.Key($"{nameof(NavigationRepo)}|{path}|{categoryName}|{nestingLevel}")
.Dependencies((_, builder) => builder.PagePath(path, PathTypeEnum.Children).ObjectType(TreeNode.OBJECT_TYPE).PageOrder()));
- When you create your DTO object from the retrieved objects add a logical statement to set the link text and URL like so.
List<NavigationItem> navItems = items.Select(node => new NavigationItem
{
LinkText = node.ClassName == CMS.DocumentEngine.Types.Company.ExternalLink.CLASS_NAME ? node.GetStringValue(nameof(CMS.DocumentEngine.Types.Company.ExternalLink.RedirectUrlText), "") : node.DocumentName,
LinkUrl = node.ClassName == CMS.DocumentEngine.Types.Company.ExternalLink.CLASS_NAME ? node.GetStringValue(nameof(CMS.DocumentEngine.Types.Company.ExternalLink.RedirectURL), "") : pageUrlRetriever.Retrieve(node).RelativePath
}).ToList();
This should get you what you're looking for.