Skip to content

Instantly share code, notes, and snippets.

@VesselinVassilev
Last active June 15, 2022 12:44
Show Gist options
  • Select an option

  • Save VesselinVassilev/9d77b3e78ee4a2705d7fe328704fe2fe to your computer and use it in GitHub Desktop.

Select an option

Save VesselinVassilev/9d77b3e78ee4a2705d7fe328704fe2fe to your computer and use it in GitHub Desktop.
Navigation view with direct links to redirect pages
@using Telerik.Sitefinity.Pages.Model;
@using Telerik.Sitefinity.Frontend.Mvc.Helpers;
@using Telerik.Sitefinity.Web;
@using Telerik.Sitefinity.Frontend.Navigation.Mvc.Models;
@model Telerik.Sitefinity.Frontend.Navigation.Mvc.Models.INavigationModel
<ul class="navbar-nav mr-auto mt-lg-0 pr-0 @Model.CssClass">
<li class="nav-close"><a href="#"><i class="fa fa-times" aria-hidden="true"></i></a></li>
@foreach (var node in Model.Nodes)
{
var activeCss = node.IsCurrentlyOpened || node.HasChildOpen ? "active" : string.Empty;
if (node.ChildNodes.Count > 0)
{
<li class="nav-item dropdown @node.CustomFields.CssClass">
<a class="nav-link dropdown-toggle @activeCss" href="#"
id='@Html.UniqueId("navbarDropdownMenuLink")' data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">@node.Title</a>
<ul class="dropdown-menu" aria-labelledby='@Html.UniqueId("navbarDropdownMenuLink")'>
@foreach (var child in node.ChildNodes)
{
var childCss = child.IsCurrentlyOpened ? "active" : string.Empty;
<li>
<a class="dropdown-item nav-link @childCss" href="@GetUrl(child)" target="@child.LinkTarget">@Html.Raw(child.Title)</a>
</li>
}
</ul>
</li>
}
else
{
<li class="nav-item @activeCss @node.CustomFields.CssClass">
<a class="nav-link" href="@GetUrl(node)" target="@node.LinkTarget">@Html.Raw(node.Title)</a>
</li>
}
}
</ul>
@functions {
public string GetUrl(NodeViewModel node)
{
var psnode = node.OriginalSiteMapNode as PageSiteNode;
if (psnode == null)
{
// this is the case where user added a link to the menu using the
// External Url tab of the Nav widget, instead of creating it as a page node in SF
return node.Url;
}
var navigateUrl = node.Url;
if (psnode.NodeType == NodeType.OuterRedirect)
{
navigateUrl = psnode.RedirectUrl;
}
else if (psnode.NodeType == NodeType.InnerRedirect)
{
navigateUrl = App.WorkWith()
.Page(psnode.LinkedNodeId)
.Get()
.GetFullUrl()
.TrimStart("~");
}
return navigateUrl;
}
}
@VesselinVassilev
Copy link
Author

VesselinVassilev commented Jun 14, 2022

@weirdyang , best is to leave this to Sitefinity - it properly generates all the open-graph tags that are used for social sharing.
https://www.progress.com/documentation/sitefinity-cms/open-graph-settings

Still, if you need to do this yourself, then best is to use the content items locations api:
https://www.progress.com/documentation/sitefinity-cms/for-developers-locations-of-content-items

@weirdyang
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment