Anders Hattestad
Mar 7, 2011
  3186
(1 votes)

Dynamic Properties with versioning V0.9

One thing I miss a lot is version on dynamic properties. I have been looking for clean solutions to add that to EPiServer, an think I have come up with an concept that can work, while we wait for CMS 7.

I have borrowed some code from Itera.Objects, that can display other properties inside one property. and used that together with Page Objects.

The concept is simple, I have one property that have all the dynamic properties inside it. When I save the page, I also save the dynamic properties inside the Page Object store. If the property is set to inherit, I delete the value from the store on this page. But my get value method checks all the stores up to the top to find the value.

image

As you can see from this picture the value for Writer is retrieved from page id 7 in en.

The pointers here is that we have to make the owner property be modified when a dynamic property is changed. This is because we need to trigger the save event. I also save the values after the page is saved, so the version is correct.

When I need to retrieve the dynamic property value I have made my own property handle. That load the values based on the page.

Hade a lot more of code in this blog post, but Live writer died, and I didn’t have any backup :(, but the core saving is done by creating a class that have the value for the property. This is because its a bit tricky to save a property data object to the store.

Code Snippet
  1. static void Instance_SavedPage(object sender, EPiServer.PageEventArgs e)
  2. {
  3.     foreach (var prop in e.Page.Property)
  4.     {
  5.         if (prop is PropertyDynamicProperties)
  6.         {
  7.             PageObjectManager pom = new PageObjectManager(e.Page);
  8.             foreach (var dynProp in (prop as PropertyDynamicProperties).AllDynamicProperties)
  9.             {
  10.                 if (dynProp.InheritValue)
  11.                 {
  12.                     pom.Delete(dynProp.Name);
  13.                 }
  14.                 else
  15.                 {
  16.                     if (dynProp.Property.IsNull)
  17.                         pom.Delete(dynProp.Name);
  18.                     else
  19.                     {
  20.                         if (dynProp.Property.IsLanguageSpecific)
  21.                             pom.Save(dynProp.Name, DynProperyStoreValue.GetObjectFromProperty(dynProp.Property, e.Page.Property), PageObject.OwnerOption.PageLanguageBranch);
  22.                         else
  23.                             pom.Save(dynProp.Name, DynProperyStoreValue.GetObjectFromProperty(dynProp.Property, e.Page.Property), PageObject.OwnerOption.PageVersion);
  24.                     }
  25.                 }
  26.                 }
  27.             }
  28.         }
  29.     }
  30. }

So i do it like this. As you can see I use the different methods of storing into the Page Object store depending on the dynamic property is unique pr languages or not.

The full code can be found in the code section.

What you need to do is to create a property of type DynamicProperties on each page type, and you are good to go.

Mar 07, 2011

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