Mari Jørgensen
Aug 25, 2010
  7409
(0 votes)

Composer and PageTypeBuilder - continued


There has been several blog posts on how to get PageTypeBuilder to play nice with EPiServer Composer, Stefan Forsberg's excellent post being one of them. Since Stefan wrote his post, new versions of both Composer (4.0) and PageTypeBuilder (1.2) has been released.

Several issues has now been resolved, but there are still some small fixes that needs to be applied, and I thought I should share them with you.  

NullReferenceExceptions
You might get errors when trying to create a new page or when visiting the Composer Tools page in admin mode.

nullreference

This is related to the way EPiServer treats the Description property of a PageType . Basically EPiServer will return an empty string if the Description is not set, while PageTypeBuilder returns null.

The quick fix for this is to change the code where Desrcription.ToString() is used:

In Dropit\Plugin\Extension\UI\Edit\ExtensionNewPage.aspx:

// Line 63 - old code
<%# TranslateDescription(Eval("name").ToString(),
       Eval("description").ToString()) %>
// Line 63 - with quick fix
<%# TranslateDescription(Eval("name").ToString(),
         Eval("description") as string ?? string.Empty) %>
 
// Line 87 - old code
<%# TranslateName(Eval("Description").ToString()).ToHtmlEncoded()%>
// Line 87 - with quick fix
<%# TranslateName(Eval("Description") as string ?? string.Empty).ToHtmlEncoded()%>
In Dropit\Plugin\Extension\UI\Admin\Controls\PageTypeList.ascx:
// Line 56 - old code
Text = '<%# Utils.TrimDescription(
    DataBinder.Eval(Container.DataItem, "Description").ToString(),60).ToHtmlEncoded() %>'
// Line 56 - with quick fix
Text = '<%# Utils.TrimDescription(
   DataBinder.Eval(Container.DataItem, "Description") as string ?? String.Empty,60).ToHtmlEncoded() %>'

These issues has been reported to support, so hopefully they will be fixed in upcoming releases (Bug #52421 reported by Frederik Viig).
Another (and a bit more boring) way around the issue is to make sure all your PageTypes has Description set.

PTB and Composer Functions
Refer to this post for a complete code sample on how to create Composer PageTypes and Functions using PageTypeBuilder.

Functions not visible in the Toolbox
I spent a lot of time investigating why the Toolbox neglected to list my functions.

When the functions are built and ready (using the approach described in the post mentioned above), you should see your new Composer functions in admin mode (ref screenshot below).

functions
It is then important to complete the following steps for each function (using ‘Save and Continue’ on each step): 

  1. Select function
  2. Select Access tab and set necessary access rights
  3. Set Rules
  4. Re-register content areas

If you miss the last step, the function will not appear in the Toolbox. Also, if you later try to re-register content areas, the function will still not be visible – seems like you need to change one of the other function properties (like Access or Rules) at the same time, in order for it to be saved. I’ve re-produced this a couple of times, but not yet reported is as a bug.

Aug 25, 2010

Comments

Andreas Thente
Andreas Thente Sep 27, 2010 05:22 PM

Hello Mari,

I´ve implemented the approach described in Dung Le´s blog post, combined with yours and got it running with some issues. I need to re-register all Composer modules after I´ve rebuilt the project and the pages containing those modules are empty. It seems like they´re not initialized after this. Have you experienced the same problem?

Great blog post by the way. I´m writing my own post right now about my experiences of Composer and PTB so this is very useful.

Best regards,
Andreas

Mari Jørgensen
Mari Jørgensen Sep 28, 2010 09:19 AM

Andreas, do you actually run Rebuild or is this also the case with 'normal' build?

Andreas Thente
Andreas Thente Sep 28, 2010 01:15 PM

I always run rebuild since I´ve worked too much with earlier versions of Composer and IISresets ;)

EDIT: Well, I have a problem with invisible properties, not invisible content functions. Probably because I inherit from the "wrong" base class. In my ascx-file, I want to inherit from PTB in some way and still use Composer functionality but the only thing (as far as i know) is to inherit from BaseContentFunction. How did you solve this?

Lars Kolsaker
Lars Kolsaker Apr 26, 2011 05:42 PM

Tested this with R2 and now you have to change line 56 in Dropit\Plugin\Extension\UI\Admin\Controls\PageTypeList.ascx
from
Text = '<%# utils.trimdescriptiondatabinder.evalcontainer.dataitem localizeddescription.tostring60.tohtmlencoded>'
to
Text = '<%# utils.trimdescriptiondatabinder.evalcontainer.dataitem localizeddescription as string string.empty60.tohtmlencoded>'

But I have been able to get the functions to appear in the toolbox by using Mari's tricks.
I'd also like to be able to set the access rights and rules programmatically, but have not dive into it yet. Anybody else

Lars Kolsaker
Lars Kolsaker Apr 26, 2011 11:00 PM

A correction to the last paragraph:
But I have NOT been able to get the functions to appear in the toolbox.......

Mari Jørgensen
Mari Jørgensen Apr 27, 2011 02:26 PM

Lars - do you get any javascript errors when loading the tool box? For more info: http://www.frederikvig.com/2010/10/avoiding-conflicts-when-using-jquery-and-episerver-composer/

Lars Kolsaker
Lars Kolsaker May 5, 2011 10:49 AM

Hi Marit

We did have a problem with JQuery and the rendering of the toolbox, but this was fixed earlier.

Please login to comment.
Latest blogs
Resource Editor - A localization management tool for Optimizely CMS

If you have worked with Optimizely CMS for any amount of time you know that managing localization through XML files can be tedious. Content type...

Per Nergård (MVP) | Feb 23, 2026

Storing JSON in a property the efficient way

Here is a little-known trick to store and retrieve JSON property data more efficiently.

Stefan Holm Olsen | Feb 23, 2026 |

Upgrade RSS Feed Integration to Optimizely CMS 13 – v3.0.0 Beta

I’ve upgraded my  RSS Feed Integration library for Optimizely CMS to support Optimizely CMS 13. Version 3.0.0 is currently released as a beta to...

David Drouin-Prince | Feb 21, 2026 |

Multi Site NuGet v2 for Optimizely CMS 13 – Breaking Changes & Migration

The beta version 2 of DavidHome.Optimizely.MultiSite is now available on NuGet: https://www.nuget.org/packages?q=DavidHome.Optimizely.MultiSite Thi...

David Drouin-Prince | Feb 21, 2026 |

Automate Your OCP Opal Tool Development with PowerShell

Creating an OCP (Optimizely Connect Platform) Opal Tool app from scratch can be time consuming and error prone. You need to set up the project...

Sanjay Kumar | Feb 21, 2026

Using HeadlessKit to build a head for an Optimizely SaaS CMS in .NET 10

Headless has a tendency to promise freedom and deliver alignment meetings. Two codebases. Two sets of models. Two teams trying very hard not to dri...

Allan Thraen | Feb 19, 2026 |