You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using Umbraco.Web;
using RJP.MultiUrlPicker.Models;
namespace Your.Project
{
using Umbraco.Core;
public static class MultiUrlPickerLinkExtensions
{
public static bool IsCurrent(this Link value)
{
if (value.Udi != null)
{
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
var currentKey = umbracoHelper.AssignedContentItem.GetKey();
var guidUdi = value.Udi as GuidUdi;
return (guidUdi?.Guid == currentKey);
}
return false;
}
}
}
I do wonder if there are performance impacts of GetKey(), I'm not sure, but the UDI doesn't seem to be in the XML cache.
The text was updated successfully, but these errors were encountered:
Or just pass the IPublishedContent to the IsCurrent method, like: @link.IsCurrent(Model)? So your method would become something like this (not tested):
I would love to see something like this - maybe even something that allowed using some of the Is-helpers that are available on IPublishedContent? E.g.:
@foreach (var link in links) {
<li class="@link.IsAncestorOrSelf(Model, "current", null)">
<a href="@link.Url">@link.Name</a>
</li>
}
I'm posting this here as it might be useful for someone else.
The extension method checks the page being viewed against the UDI stored on the link.
It can then be used as follows:
<a class="@(link.IsCurrent() ? "current" : null)" href="@link.Url">@link.Name</a>
I do wonder if there are performance impacts of
GetKey()
, I'm not sure, but the UDI doesn't seem to be in the XML cache.The text was updated successfully, but these errors were encountered: