Created
April 18, 2025 05:53
-
-
Save AndyButland/37ec92963aa6a4b210d4141a2b004585 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Umbraco.Cms.Core.Models; | |
using Umbraco.Cms.Core.Strings; | |
namespace MyProject.Web.Customization; | |
public class SoftwarePageUrlSegmentProvider : IUrlSegmentProvider | |
{ | |
private readonly IUrlSegmentProvider _provider; | |
public SoftwarePageUrlSegmentProvider(IShortStringHelper stringHelper) => _provider = new DefaultUrlSegmentProvider(stringHelper); | |
public bool AllowAdditionalSegments => true; // Ensure that the default URL segment provider is still called. | |
public string? GetUrlSegment(IContentBase content, string? culture = null) | |
{ | |
// Only apply this provider for software pages. | |
if (SoftwarePageUrlHelper.IsSoftwarePage(content.ContentType.Alias, content.Name) is false) | |
{ | |
return null; | |
} | |
// Remove "-software" from the default URL segment and register that as a URL segment too. | |
// As this IUrlSegmentProvider is not terminating, the default URL segment provider will still be called and include | |
// the segment with the "-software" suffix too. | |
var segment = _provider.GetUrlSegment(content, culture); | |
return segment?.Replace("-software", string.Empty); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment