sharepointsharepoint-2007publishingwcm

How to dynamically switch PageLayout and MasterPage of SharePoint Publishing page?


To improve both the editing and displaying experience of SharePoint WCM Publishing pages I would like to be able to switch to a special set of Masterpage/PageLayout when in edit mode.

So in /_catalogs/masterpage I want to have:

MyMasterpage.master - masterpage for display mode MyMasterpage-edit.master - masterpage for edit mode, only use if available MyPageLayout.aspx - pagelayout for display mode MyPageLayout-edit.aspx - pagelayout for edit mode, only use if available

When I create a new publishing page in the Pages library, I select the MyPageLayout page layout.

When rendering the page I would like to detect if I'm in Edit of Display mode, just like the server control does. This control executes the following code to determine the render mode:

private void calculateShouldRender()
{
    SPControlMode contextualFormModeFromPostedForm = ConsoleUtilities.GetContextualFormModeFromPostedForm();
    if ((SPControlMode.Display == contextualFormModeFromPostedForm) && (PageDisplayMode.Display == this.PageDisplayMode))
    {
        this.shouldRender = true;
    }
    else if ((SPControlMode.Edit == contextualFormModeFromPostedForm) && (PageDisplayMode.Edit == this.PageDisplayMode))
    {
        this.shouldRender = true;
    }
    else
    {
        this.shouldRender = false;
    }
    this.Visible = this.shouldRender;
}

If the render mode is Edit, I want to switch to the MyMasterpage-edit.master materpage and the MyPageLayout-edit.aspx pagelayout.

I could make a big switch in the masterpage and pagelayout controlled by server controls, but I would like to split resposibilities. A SharePoint Analist can create optimal edit mode pages, and a front end developer can create clean and beautiful display mode pages without all the editing clutter.

Any ideas on how to accomplish this? Masterpage switching does not seem the problem, I once wrote a blogpost on this. The difficult thing seems the switching of the page layout.


Solution

  • The definitive answer to this question is now "baked" into a product which we call DualLayout for SharePoint! Our approach solves all your SharePoint WCM design nightmare:

    Check it out at http://www.macaw.nl/Het+Bedrijf/Producten/Macaw+DualLayout+for+SharePoint.aspx, see the blog posts in the blog roll of that page for detailed background information.