Is there a way that I can hide all languages from this list that do not have a url configured? I’ve tried doing this in my IUrlProvider
in the GetOtherUrls
method with no success. It seems regardless of what I do in there it will still list all languages that are enabled in the Umbraco instance.
Hi there!
I don’t have the full solution, but I might have a pointer for you. I used a notification handler to modify this particular list of URLs, in my case to show a custom message for content pages without a template. It looks like this:
public class DisableUrlsNotificationHandler : INotificationHandler<SendingContentNotification>
{
public void Handle(SendingContentNotification notification)
{
ContentItemDisplay contentItem = notification.Content;
if (contentItem != null && contentItem.AllowedTemplates?.Any() is not true)
{
var urls = new List<UrlInfo>();
var urlCultures = contentItem.Urls?.Select(x => x.Culture).Distinct().ToList() ?? [];
foreach (var culture in urlCultures)
{
urls.Add(UrlInfo.Message("This page has no URLs", culture));
}
contentItem.Urls = [.. urls];
}
}
}
You can use a similar notification handler to check the existing urls and modify them or even remove them completely.
1 Like
@D-Inventor That works perfectly - thanks for sharing.
Here is my final working solution…
public class SendingContentNotificationHandler : INotificationHandler<SendingContentNotification>
{
public void Handle(SendingContentNotification notification)
{
ContentItemDisplay contentItem = notification.Content;
contentItem.Urls = contentItem.Urls?.Where(c => c.IsUrl).ToArray();
}
}