Stefan Forsberg
May 7, 2009
  6310
(0 votes)

Page Provider – Part three

Mapping your data to properties on the episerverpage is a fairly simple process. In the GetLocalPage method we simple use the SetValue on our created PageData object.

The standard page has two properties called MainBody and  SecondaryBody so let’s set some values on those properties.

protected override EPiServer.Core.PageData GetLocalPage(EPiServer.Core.PageReference pageLink, EPiServer.Core.ILanguageSelector languageSelector)
{
    PageData pageData = new PageData();
 
    Development.DataAbstraction.SimplePage activeSimplePage = GetSimplePage(pageLink);
    
    // Finds the parent to our page.
    PageReference parentLink = (pageLink.ID == parentPage.ID) ? base.EntryPoint : base.ConstructPageReference(parentPage.ID);
 
    base.InitializePageData(
        pageData, 
        activeSimplePage.Name, 
        standardPageType.Name, 
        activeSimplePage.Guid, 
        pageLink, 
        parentLink, 
        new List<string>() {}
        );
 
    pageData.SetValue("MainBody", "Some text");
    pageData.SetValue("SecondaryBody", "Some other text");
 
    return pageData;
}

01

This works well for simple string based properties  (both MainBody and SecondaryBody are of type xhtml string). So let’s try to work with a more complex property type, for instance the link collection. To do this we start with adding a property of that type called Links to our standard page page type.

To get a feel for how this works let’s start with just setting the property to some string value and see what happens.

   1: pageData.SetValue("Links", "Link1");

This leads to the exception System.ArgumentException: Passed object must be of type LinkItemCollection. So apparently we need to create a LinkItemCollection and map it to the property data.

EPiServer.SpecializedProperties.LinkItemCollection links = new EPiServer.SpecializedProperties.LinkItemCollection();
 
EPiServer.SpecializedProperties.LinkItem linkItem = new EPiServer.SpecializedProperties.LinkItem();
linkItem.Href = "http://www.aftonbladet.se";
linkItem.Text = "Aftonbladet";
 
links.Add(linkItem);
 
linkItem = new EPiServer.SpecializedProperties.LinkItem();
linkItem.Href = "http://www.idg.se";
linkItem.Text = "IDG";
 
links.Add(linkItem);
 
pageData.SetValue("Links", links);

02

This is a somewhat unlikely scenario (to create the links programmatically that is). A more likely task is that the customer wants to add additional info to their data. Say for instance that the customer wants to add some links to their products that they for some reason don’t want or are unable to store in their product database.

What we’d do then is to give the page provider the capabilities to edit the page and when the user saves the page we save the property value of the link collection to some repository and then build logic to fetch the same data on the loading of the page (GetLocalPage).

This is what we’ll explore in the next post.

May 07, 2009

Comments

Please login to comment.
Latest blogs
Opti ID overview

Opti ID allows you to log in once and switch between Optimizely products using Okta, Entra ID, or a local account. You can also manage all your use...

K Khan | Jul 26, 2024

Getting Started with Optimizely SaaS using Next.js Starter App - Extend a component - Part 3

This is the final part of our Optimizely SaaS CMS proof-of-concept (POC) blog series. In this post, we'll dive into extending a component within th...

Raghavendra Murthy | Jul 23, 2024 | Syndicated blog

Optimizely Graph – Faceting with Geta Categories

Overview As Optimizely Graph (and Content Cloud SaaS) makes its global debut, it is known that there are going to be some bugs and quirks. One of t...

Eric Markson | Jul 22, 2024 | Syndicated blog

Integration Bynder (DAM) with Optimizely

Bynder is a comprehensive digital asset management (DAM) platform that enables businesses to efficiently manage, store, organize, and share their...

Sanjay Kumar | Jul 22, 2024

Frontend Hosting for SaaS CMS Solutions

Introduction Now that CMS SaaS Core has gone into general availability, it is a good time to start discussing where to host the head. SaaS Core is...

Minesh Shah (Netcel) | Jul 20, 2024

Optimizely London Dev Meetup 11th July 2024

On 11th July 2024 in London Niteco and Netcel along with Optimizely ran the London Developer meetup. There was an great agenda of talks that we put...

Scott Reed | Jul 19, 2024