XperienceCommunity.PageTemplateUtilities 1.0.0

dotnet add package XperienceCommunity.PageTemplateUtilities --version 1.0.0                
NuGet\Install-Package XperienceCommunity.PageTemplateUtilities -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="XperienceCommunity.PageTemplateUtilities" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add XperienceCommunity.PageTemplateUtilities --version 1.0.0                
#r "nuget: XperienceCommunity.PageTemplateUtilities, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install XperienceCommunity.PageTemplateUtilities as a Cake Addin
#addin nuget:?package=XperienceCommunity.PageTemplateUtilities&version=1.0.0

// Install XperienceCommunity.PageTemplateUtilities as a Cake Tool
#tool nuget:?package=XperienceCommunity.PageTemplateUtilities&version=1.0.0                

Xperience Page Template Utilities

NuGet Package

Utilities to help quickly create and register MVC Page Templates in Kentico Xperience

Dependencies

This package is compatible with ASP.NET Core 3.1 → ASP.NET Core 5 and is designed to be used with .NET Core / .NET 5 Console applications integrated with Kentico Xperience 13.0.

How to Use?

  1. First, install the NuGet package in your ASP.NET Core project

    dotnet add package XperienceCommunity.PageTemplateUtilities
    
  2. Create an implementation of PageTypePageTemplateFilter for a given Page Type and register some Page Templates

    [assembly: RegisterPageTemplate(
        "Sandbox.HomePage_Default",
        "Home Page (Default)",
        typeof(BasicContentPageTemplateProperties),
        "~/Features/Home/Sandbox.HomePage_Default.cshtml")]
    
    public class HomePageTemplateFilter : PageTypePageTemplateFilter
    {
         public override string PageTypeClassName => "Sandbox.HomePage";
    }
    
  3. Register all IPageTemplateFilter implementations with the IServiceCollection

    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddPageTemplateFilters(Assembly.GetExecutingAssembly());
        }
    }
    

How Does It Work?

The PageTypePageTemplateFilter is simplest if your Page Templates follow some conventions, but allows for full customization.

In the example below, Home Page (Default) will match the filter and be allowed for selection for Sandbox.HomePage Page Types, but Home Page (Featured) does not have an Identifier (Sandbox_PageTemplate_HomePage_Featured) that matches the prefix of Sandbox.HomePage_, so it will not be displayed for selection for Sandbox.HomePage Page Types. It would need to be changed to Sandbox.HomePage_Featured to match the default filter, which follows the pattern of matching Page Templates with a Identifier prefix of $"{PageTypeClassName}_".

[assembly: RegisterPageTemplate(
    "Sandbox.HomePage_Default",
    "Home Page (Default)",
    typeof(BasicContentPageTemplateProperties),
    "~/Features/Home/Sandbox.HomePage_Default.cshtml")]

[assembly: RegisterPageTemplate(
    "Sandbox_PageTemplate_HomePage_Featured",
    "Home Page (Featured)",
    typeof(BasicContentPageTemplateProperties),
    "~/Features/Home/Sandbox_HomePage_Featured.cshtml")]

public class HomePageTemplateFilter : PageTypePageTemplateFilter
{
    public override string PageTypeClassName => HomePage.CLASS_NAME;
}

The filter can be overridden to allow you to match however you would like. It has a signature of:

Func<PageTemplateDefinition, PageTemplateFilterContext, string, bool> PageTemplateFilterBy

The customization below would match an Identifier like _Sandbox.HomePage-Default:

public class HomePageTemplateFilter : PageTypePageTemplateFilter
{
    public override string PageTypeClassName => HomePage.CLASS_NAME;

    public override Func<PageTemplateDefinition, PageTemplateFilterContext, string, bool> PageTemplateFilterBy { get; } =
        (definition, context, className) => definition.Identifier.StartsWith($"_{className}-", StringComparison.OrdinalIgnoreCase);
}

We could even skip using the className entirely and match against the definition or context with some hardcoded values, but at that point it's probably best to implement the IPageTemplateFilter directly.

References

Kentico Xperience

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on XperienceCommunity.PageTemplateUtilities:

Package Downloads
XperienceCommunity.Baseline.Core.Library.KX13

The Baseline a set of Core Systems, Tools, and Structure to ensure a superior Kentico Website that's easy to migrate, for Kentico Xperience 13 and eventually Xperience by Kentico

XperienceCommunity.Baseline.Core.RCL.KX13

The Baseline a set of Core Systems, Tools, and Structure to ensure a superior Kentico Website that's easy to migrate, for Kentico Xperience 13 and eventually Xperience by Kentico

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 31,395 3/20/2021
1.0.0-alpha-1 351 3/20/2021