ZimmertyZim
08/30/2023, 10:23 AMpublic static class IPublishedContentExtensions
{
    public static string TitleOrPageName(this IPublishedContent content, string titleAlias = "navigationLabel")
    {
        return content.HasValue(titleAlias) ? content.GetPropertyValue<string>(titleAlias) : content.Name;
    }
    public static int GetYearFromDateOrLatest(this IPublishedContent content, string fieldAlias)
    {
        return content.HasValue(fieldAlias) ? content.GetPropertyValue<DateTime>(fieldAlias).Year : DateTime.Now.Year;
    }
}using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Extensions;
namespace MyApplication.Web.Extensions;
public static string TitleOrPageName(this IPublishedContent content, string titleAlias = "navigationLabel")
{
    return content.HasValue(alias: titleAlias) ? content.Value<string>(_publishedValueFallback, titleAlias) : content.Name;
}Rachel D
08/30/2023, 10:32 AMcsharp
private static IPublishedValueFallback PublishedValueFallback { get; } =
    StaticServiceProvider.Instance.GetRequiredService<IPublishedValueFallback>();ZimmertyZim
08/30/2023, 10:35 AMRachel D
08/30/2023, 10:35 AMZimmertyZim
08/30/2023, 10:38 AMkdx-perbol
08/30/2023, 12:01 PMZimmertyZim
08/30/2023, 12:20 PMA hub and casual space for you to interact with fellow community members and learn more about Umbraco!
Powered by