How to dynamically switch PageLayout and MasterPage of SharePoint Publishing page

publishingsharepointsharepoint-2007wcm

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.

Best Answer

I think you would be fighting SharePoint if you continue down that route, I fear it would also become something of a support nightmare as it becomes less clear where problems lie, or remembering to make changes in both (or all four!) places when something is updated.

You can have controls appear or hide depending on the editmode of a page so what is shown to the user is totally different but all the code for a page is still in one place.

Investigate the editmodepanel.

<publishingwebcontrols:editmodepanel ID="Editmodepanel1" runat="server">
   <link id="Link2" rel=Stylesheet href="<% $SPUrl:~sitecollection/EditMode.css %>" runat="server" type="text/css" />
</publishingwebcontrols:editmodepanel>

I realise that is not quite what you asked... but I find fighting SharePoint is a losing battle you just have to work with its 'way'.

Related Topic