XperienceCommunity.PageTemplateUtilities
1.0.0-alpha-1
See the version list below for details.
dotnet add package XperienceCommunity.PageTemplateUtilities --version 1.0.0-alpha-1
NuGet\Install-Package XperienceCommunity.PageTemplateUtilities -Version 1.0.0-alpha-1
<PackageReference Include="XperienceCommunity.PageTemplateUtilities" Version="1.0.0-alpha-1" />
paket add XperienceCommunity.PageTemplateUtilities --version 1.0.0-alpha-1
#r "nuget: XperienceCommunity.PageTemplateUtilities, 1.0.0-alpha-1"
// Install XperienceCommunity.PageTemplateUtilities as a Cake Addin #addin nuget:?package=XperienceCommunity.PageTemplateUtilities&version=1.0.0-alpha-1&prerelease // Install XperienceCommunity.PageTemplateUtilities as a Cake Tool #tool nuget:?package=XperienceCommunity.PageTemplateUtilities&version=1.0.0-alpha-1&prerelease
Xperience Page Template Utilities
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?
First, install the NuGet package in your ASP.NET Core project
dotnet add package XperienceCommunity.PageTemplateUtilities
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"; }
Register all
IPageTemplateFilter
implementations with theIServiceCollection
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 | Versions 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. |
-
.NETCoreApp 3.1
- Kentico.Xperience.AspNetCore.WebApp (>= 13.0.0 && < 13.1.0)
- Scrutor (>= 3.3.0)
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,398 | 3/20/2021 |
1.0.0-alpha-1 | 351 | 3/20/2021 |