The Problem: fURL, page ID's and Templates

The Friendly URL Rewrite provider used by EPiServer CMS 5 today does not allow a developer to connect a template to a specific page ID. A scenario when you might want to do this could for instance be if you wanted to use the same page content in several templates. A live example where this is used is the EPiStore Module where several templates have logic that is not connected to a specific page.

The Solution: Page Extensions

To connect a template to a page ID you can use the page extension CustomPageLink. What you need to do is to create your own base class derived from EPiServer.TemplatePage and call the TemplatePage constructor with the CustomPageLink flag.

The call to the constructor could look as follows:

CopyC#
public CustomPageLinkTemplate(): base(CustomPageLink.OptionFlag, 0)
Example of a complete base class derived from EPiServer.TemplatePage
CopyC#
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using EPiServer.Web.PageExtensions;

namespace EPiServer.Example
{
    public class CustomPageLinkTemplate : EPiServer.TemplatePage
    {
        public CustomPageLinkTemplate(): base(CustomPageLink.OptionFlag, 0)
        {

        }
    }
}

The "0" in the call to the base constructor ensures that you don't disable any functionality provided by the base class.

To call a page based on this custom class with content from another page, you need to use the custompageid parameter in the querystring. If we had a page template named customsample.aspx and wanted to call it with the contents of a page with the ID of 5 the call would look as follows:

/customsample.aspx?custompageid=5

To try it out you can use CurrentPage.PageName in the markup. The call will display the name of the page with the id 5 and not the name of the template we are currently browsing.