![]() |
VOOZH | about |
dotnet add package XperienceCommunity.PageTemplateUtilities --version 1.0.0
NuGet\Install-Package XperienceCommunity.PageTemplateUtilities -Version 1.0.0
<PackageReference Include="XperienceCommunity.PageTemplateUtilities" Version="1.0.0" />
<PackageVersion Include="XperienceCommunity.PageTemplateUtilities" Version="1.0.0" />Directory.Packages.props
<PackageReference Include="XperienceCommunity.PageTemplateUtilities" />Project file
paket add XperienceCommunity.PageTemplateUtilities --version 1.0.0
#r "nuget: XperienceCommunity.PageTemplateUtilities, 1.0.0"
#:package XperienceCommunity.PageTemplateUtilities@1.0.0
#addin nuget:?package=XperienceCommunity.PageTemplateUtilities&version=1.0.0Install as a Cake Addin
#tool nuget:?package=XperienceCommunity.PageTemplateUtilities&version=1.0.0Install as a Cake Tool
Utilities to help quickly create and register MVC Page Templates in Kentico Xperience
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.
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 the IServiceCollection
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddPageTemplateFilters(Assembly.GetExecutingAssembly());
}
}
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.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp3.1 netcoreapp3.1 is compatible. |
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 |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 53,450 | 3/20/2021 |
| 1.0.0-alpha-1 | 595 | 3/20/2021 |