Container pages for EPiServer CMS 6 based on PageTypeBuilder
Remember the new feature called Container-pages that came with CMS 6 R2 edition? If you don’t remember it is ok cause most of the project never use them since PageTypeBuilder did not support that. I say did cause I am not that updated on PageTypeBuilder at the moment.
But I think they are a nice feature that I also promote at developer courses. When I build new websites and structure the content I tend to use them and in the early days of EPiServer we used ordinary pagtypes for this. If you do not know what they are I suggest you read the blog post that Linus wrote when this feature were released, http://world.episerver.com/Blogs/Linus-Ekstrom/Dates/2011/3/Container-pages/
So, a quick answer is: A PageType without a template!
They will have a special rendering inside edit-mode looking like the image below and also other nice features that Linus mentioned in his blog post.
Render Container-pages with PageTypeBuilder
The problem with PageTypeBuilder is that by default if you leave the “Filename” empty it will fallback to default.aspx or something like that. So we need to force the website to render specific PageTypes like container pages. This can be done in Global.asax.
Add EventHandlers to Global.asax
We need to add two new eventhandlers to global.asax, these will be added to Application_Start.
Next we create a class for handling all the PageTypes that should be rendered as ContainerPages.
Here we use PageTypeResolver from PageTypeBuilder to get our Id:s for our different pagetypes.
Next we add some logic to the newly created eventhandlers, so we open global.asax again.
Our code in global.asax
Finally we need to add some code to our PageTypes, telling them that the do not have any Template:
That is about it.
Not sure this is the best way or if I am doing anything wrong but it looks like it is working ok. It also might work with only the last piece of code, so please give feedback!