SaaS CMS has officially launched! Learn more now.

bartek.tatkowski@nansen.se
Mar 23, 2010
  2998
(0 votes)

How to get the PageTypeName property without creating a page instance

In a project we’re currently working on here at Nansen we stumbled upon the need to get the name of a page type without having an actual reference to page of that type.

Since we’re using Joel’s PageTypeBuilder, getting the name was a simple task of reflecting the PageTypeAttributes object.

public static string GetPageTypeName<T>() where T : TypedPageData
{
    System.Reflection.MemberInfo memberInfo = typeof(T);
    object[] attributes =  memberInfo.GetCustomAttributes(typeof(PageTypeAttribute), false); 
    if (attributes.Count() > 0)
    {
        PageTypeAttribute pta = attributes.First() as PageTypeAttribute;
        return pta.Name;
    } 
    return string.Empty;
}
Mar 23, 2010

Comments

Please login to comment.
Latest blogs
Optimizely SaaS CMS Concepts and Terminologies

Whether you're a new user of Optimizely CMS or a veteran who have been through the evolution of it, the SaaS CMS is bringing some new concepts and...

Patrick Lam | Jul 15, 2024

How to have a link plugin with extra link id attribute in TinyMce

Introduce Optimizely CMS Editing is using TinyMce for editing rich-text content. We need to use this control a lot in CMS site for kind of WYSWYG...

Binh Nguyen Thi | Jul 13, 2024

Create your first demo site with Optimizely SaaS/Visual Builder

Hello everyone, We are very excited about the launch of our SaaS CMS and the new Visual Builder that comes with it. Since it is the first time you'...

Patrick Lam | Jul 11, 2024

Integrate a CMP workflow step with CMS

As you might know Optimizely has an integration where you can create and edit pages in the CMS directly from the CMP. One of the benefits of this i...

Marcus Hoffmann | Jul 10, 2024