XperienceCommunity.LinkablePages 3.0.0

dotnet add package XperienceCommunity.LinkablePages --version 3.0.0
NuGet\Install-Package XperienceCommunity.LinkablePages -Version 3.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.LinkablePages" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add XperienceCommunity.LinkablePages --version 3.0.0
#r "nuget: XperienceCommunity.LinkablePages, 3.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.LinkablePages as a Cake Addin
#addin nuget:?package=XperienceCommunity.LinkablePages&version=3.0.0

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

GitHub Actions CI: Build

Publish Packages to NuGet

Packages

LinkablePages

NuGet Package

Kentico Xperience 13.0 custom module to protect pages referenced in code from deletion and shared abstractions for linkable pages.

This package is compatible with .NET Standard 2.0 libraries integrated with Kentico Xperience 13.0.

PageLinkTagHelpers

NuGet Package

Kentico Xperience 13.0 ASP.NET Core Tag Helper that generates links to predefined pages using their NodeGUID values, and extension methods for registering dependencies in ASP.NET Core.

This package is compatible with ASP.NET Core 3.1+ applications or libraries integrated with Kentico Xperience 13.0.

How to Use?

  1. Install the XperienceCommunity.LinkablePages NuGet package in a class library shared by your ASP.NET Core and CMS applications:

    dotnet add package XperienceCommunity.LinkablePages
    
  2. In the shared class library, create a class implementing the ILinkablePage where you define pages that are available to the tag helper:

    Populate the Guid values with the NodeGUID of each page in the content tree that you need to link to in your application.

    using XperienceCommunity.LinkablePages;
    
    public namespace Sandbox.Shared
    {
       public class LinkablePage : ILinkablePage
       {
           public static LinkablePage Home { get; } = new LinkablePage(new Guid("..."));
           public static LinkablePage Store { get; } = new LinkablePage(new Guid("..."));
           public static LinkablePage ContactUs { get; } = new LinkablePage(new Guid("..."));
           public static LinkablePage TermsOfUse { get; } = new LinkablePage(new Guid("..."));
    
           public Guid NodeGUID { get; }
    
           protected LinkablePage(Guid nodeGUID) => NodeGUID = nodeGUID;
    
           public static IReadOnlyList<LinkablePage> All { get; } = new List<LinkablePage>
           {
               Home,
               Store,
               ContactUs,
               TermsOfUse
           };
       }
    }
    
  3. In the shared class library, create an implementation of the ILinkablePageInventory interface, which will be used to determine which Pages in the application should be protected:

    using XperienceCommunity.LinkablePages;
    
    public class LinkablePageInventory : ILinkablePageInventory
    {
        public bool IsLinkablePage(TreeNode page)
        {
            return LinkablePage.All.Any(p => p.NodeGUID == page.NodeGUID);
        }
    }
    
  4. Install the XperienceCommunity.PageLinkTagHelpers NuGet package in your ASP.NET Core project:

    dotnet add package XperienceCommunity.PageLinkTagHelpers
    
  5. Add the @addTagHelper directive to your _ViewImports.cshtml file:

    (optional) Add your LinkablePage class's namespace to your _ViewImports.cshtml file (e.g., Sandbox.Shared).

    // Add this using to make LinkablePages easy to access in Views
    @using Sandbox.Shared
    
    @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
    @addTagHelper *, Kentico.Content.Web.Mvc
    @addTagHelper *, Kentico.Web.Mvc
    @addTagHelper *, DancingGoatCore
    
    // Add this directive to use the Tag Helper
    @addTagHelper *, XperienceCommunity.PageLinkTagHelpers
    
  6. Register the library with ASP.NET Core DI:

    using XperienceCommunity.LinkablePages;
    
    public void ConfigureServices(IServiceCollection services)
    {
        // Use standard registration
        services
          .AddXperienceCommunityPageLinks()
          .AddXperienceCommunityPageLinksProtection<LinkablePageInventory>();
    
        // or use a custom implementation of ILinkablePageLinkRetriever
        services
          .AddXperienceCommunityPageLinks<MyCustomLinkablePageLinkRetriever>()
          .AddXperienceCommunityPageLinksProtection<LinkablePageInventory>();
    }
    
  7. Add the data protection custom module registration to your ASP.NET Core application (in Startup.cs or wherever you register your dependencies):

    using XperienceCommunity.LinkablePages;
    
    [assembly: RegisterModule(typeof(LinkablePageProtectionModule))]
    
  8. Use the xp-page-link tag helper in an <a> element in a Razor View:

    <a href="" xp-page-link="LinkablePage.Home">
      <img
        src="/getmedia/10d5e094-d9aa-4edf-940d-098ca69b5f77/logo.png"
        alt="..."
      />
    </a>
    
  9. Create a custom module class in your CMS application to register the LinkablePageProtectionModule and the ILinkablePageInventory implementation:

    using XperienceCommunity.LinkablePages;
    
    // Registers this custom module class
    [assembly: RegisterModule(typeof(DependencyRegistrationModule))]
    
    // Registers the library's custom module class
    [assembly: RegisterModule(typeof(LinkablePageProtectionModule))]
    
    namespace CMSApp
    {
        public class DependencyRegistrationModule : Module
        {
            public DependencyRegistrationModule() : base(nameof(DependencyRegistrationModule))
            {
    
            }
    
            protected override void OnPreInit()
            {
                base.OnPreInit();
    
                // Registers the ILinkablePageInventory implementation used by the LinkablePageProtectionModule
                Service.Use<ILinkablePageInventory, LinkablePageInventory>();
            }
        }
    }
    
  10. Use Kentico Xperience's Content Staging to keep your LinkablePage NodeGUID values valid between different environments.

Usage

Simple

Razor (assuming the ContactUs Page has a DocumentName of "Contact Us"):

<a href="" xp-page-link="LinkablePage.ContactUs"></a>

Generated HTML will set the child content, href and title attributes:

<a href="/contact-us" title="Contact Us">Contact Us</a>

Custom Content

Razor (assuming the ContactUs Page has a DocumentName of "Contact Us"):

<a href="" title="Please contact us" xp-page-link="LinkablePage.ContactUs">
  <img src="..." />
</a>

Generated HTML will keep the child content and only set the href and title attributes:

<a href="/contact-us" title="Please contact us">
  <img src="..." />
</a>

Empty Title Attribute with Child Content

Razor:

<a href="" title="" xp-page-link="LinkablePage.ContactUs">
  No title necessary!
</a>

Generated HTML will not populate the title attribute, assuming the child content provides some text:

<a href="/contact-us" title=""> No title necessary! </a>

Empty Title Attribute with No Child Content

Razor (assuming the ContactUs Page has a DocumentName of "Contact Us"):

<a href="" title="" xp-page-link="LinkablePage.ContactUs"> </a>

Generated HTML will populate the title for accessibility:

<a href="/contact-us" title="Contact Us"> Contact Us </a>

Query String Parameters

Razor:

<a
  href=""
  xp-page-link="LinkablePage.ContactUs"
  title="Please contact us"
  xp-page-link-query-params="@(new() { { "parameter": "value" } })">
    Contact us for help!
</a>

Generated HTML will include query string parameters in the href, and set the title attribute/child content as appropriate:

<a href="/contact-us?parameter=value" title="Please contact us">
   Contact us for help!
</a>

Contributions

If you discover a problem, please open an issue.

If you would like contribute to the code or documentation, please open a pull request.

References

.NET

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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on XperienceCommunity.LinkablePages:

Package Downloads
XperienceCommunity.PageLinkTagHelpers

Provides ASP.NET Core Tag Helpers for Kentico Xperience 13.0 applications to help developers easily generate links to pages in the content tree.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.0 2,458 10/10/2022
3.0.0-prerelease-8-2 175 10/10/2022
2.0.0 717 8/20/2022
2.0.0-prerelease-7-1 146 8/20/2022