Take the community feedback survey now.

Magnus Rahl
Jan 29, 2009
  4847
(0 votes)

Dynamic Content goes personal

It started out as a simple Dynamic Content element which displayed the name of the user viewing the page, to enable editors to add greetings like “Hello [user name], welcome to the page!”. I then realized there may be many other uses for that type of personalized Dynamic Content.

Using my own implementation of Anders Hattestad’s Dynamic Content base class (see this blog entry) I created an interface, a custom edit control and a few simple implementations of the interface that output basic user information. The implementation of the rendering class, however, will find all implementations of the interface in any of the application bin folder’s dlls using reflection.

Examples

Here's an example of how it might look (I tried to insert screen dumps here but EPiServer World does not seem to support it):

Hello Test!

This personal information, like your users first name in the headline and your email address testmail@domain.tld are displayed by the ProfileInfo Dynamic Content. It can also display information about other users, like the user with username sogeti whose title is not set.

And in edit mode:

Hello [DynamicContent:ProfileInfo]!

This personal information, like your users first name in the headline and your email address [DynamicContent:ProfileInfo]are displayed by the ProfileInfo Dynamic Content. It can also display information about other users, like the user with username [DynamicContent:ProfileInfo]whose title is [DynamicContent:ProfileInfo].

Each “instance” can be configured to display information either about a specific user or the user viewing the page. Based on the interface implementations available the editor can choose one to display, and a fallback, should the first one return empty (a property not set, user is anonymous etc.). The fallback may be another interface implementation or a free text string, as in the example “not set” above. For an anonymous user the same message, in this case, looks like this:

Hello Anonymous!

This personal information, like your users first name in the headline and your email address Email not set are displayed by the ProfileInfo Dynamic Content. It can also display information about other users, like the user with username sogeti whose title is not set.

The interface also includes a way to replace an existing implementation with a new one if, say, you would want the username to output backwards or rendered as an image instead. The class generating the email link (“-“ for the anonymous user is the fallback text) is actually a replacement implementation which inherits from the original Email implementation and replaces it:

   1: /// 
   2: /// Class that displays the email address as a mailto link
   3: /// 
   4: public class EmailAsLink : Email
   5: {
   6:     public override string Render(EPiServer.PageBase hostPage, EPiServer.Personalization.EPiServerProfile profile)
   7:     {
   8:         if (!profile.IsAnonymous && !string.IsNullOrEmpty(profile.Email))
   9:         {
  10:             return string.Format("{0}", profile.Email);
  11:         }
  12:         else
  13:         {
  14:             // Return null, the selected fallback contents will be used
  15:             return null;
  16:         }
  17:     }
  18:  
  19:     public override Type OverridesType
  20:     {
  21:         get
  22:         {
  23:             // Replace the standard email implementation
  24:             return typeof(Email);
  25:         }
  26:     }
  27: }
  28: }

And strictly there is no limitation to just the profile properties of the user. Using the information in the PageBase and EPiServerProfile objects fed to the interface it’s possible to output the user’s community mypage portrait or a message-of-the-day stored in a dynamic property.

Source code

The source code is available here. A short explanation of the files:

DynamicContentBase.cs: Base class for dynamic content, as mentioned in the beginning of this post.

IProfileProperty.cs: Interface that has to be implemented by classes rendering information in the ProfileInfo Dynamic Content.

ProfileInfo.cs: The actual Dynamic Content implementation. Calls all available IProfileProperty implementations at render time and in edit mode to populate the drop down lists of the dialog.

ProfileInfoFactory.cs: Singleton class that is responsible for finding IProfileProperty implementations at applicaiton start and sorting out replacements.

DefaultImplementaions.cs: Contains a base class for outputing simple string properties of the user profile, as well as several implementations for standard properties such as UserName, FirstName, LastName etc.

EmailAsLink.cs: Replaces the Email implementation in DefaultImplementations.cs, outputing a mailto link instead of just the email text.

And remember: You still have to add the Dynamic Content class ProfileInfo to the episerver/dynamicContent section of your web config file.

Jan 29, 2009

Comments

Please login to comment.
Latest blogs
A day in the life of an Optimizely OMVP - Opticon London 2025

This installment of a day in the life of an Optimizely OMVP gives an in-depth coverage of my trip down to London to attend Opticon London 2025 held...

Graham Carr | Oct 2, 2025

Optimizely Web Experimentation Using Real-Time Segments: A Step-by-Step Guide

  Introduction Personalization has become de facto standard for any digital channel to improve the user's engagement KPI’s.  Personalization uses...

Ratish | Oct 1, 2025 |

Trigger DXP Warmup Locally to Catch Bugs & Performance Issues Early

Here’s our documentation on warmup in DXP : 🔗 https://docs.developers.optimizely.com/digital-experience-platform/docs/warming-up-sites What I didn...

dada | Sep 29, 2025

Creating Opal Tools for Stott Robots Handler

This summer, the Netcel Development team and I took part in Optimizely’s Opal Hackathon. The challenge from Optimizely was to extend Opal’s abiliti...

Mark Stott | Sep 28, 2025

Integrating Commerce Search v3 (Vertex AI) with Optimizely Configured Commerce

Introduction This blog provides a technical guide for integrating Commerce Search v3, which leverages Google Cloud's Vertex AI Search, into an...

Vaibhav | Sep 27, 2025

A day in the life of an Optimizely MVP - Opti Graph Extensions add-on v1.0.0 released

I am pleased to announce that the official v1.0.0 of the Opti Graph Extensions add-on has now been released and is generally available. Refer to my...

Graham Carr | Sep 25, 2025