none
Dynamic switch of PageLayout in runtime

    Question

  • Hi,

    I'm having a publishing web where I'm using pagelayouts with contenttypes.

    What I'm trying to do, is to switch pagelayout for the site, before it loads.

    An example would be, if we have typed ?Layout=1 in the query string is shows the page layout associated with value 1 and of we type 2 we would see another page layout. The pagelayouts uses the same content type and the only change in the layout, is the design markup html is different. It has the same webpartzones and so forth.

    I've heard that an PageAdapter is a possible way?

    What i thought would be most easy is to inherit PublishingLayoutPage and use it for the layouts which sould use the functionality, but I can't find any possible way.

    Thanks!


    Friday, March 02, 2012 7:01 AM

Answers

All replies

  • LarsU_DK,

    You can try the following steps:
    Create class derived from Microsoft.SharePoint.Publishing.PublishingLayoutPage
    At OnPreInit event of this new class change the page MasterPage.
    Create new page layout and change the value of "Inherits" attribute for Page directive to points to your class
    Create your publishing page from the new page layout
    To change the master page use this following code:
    protected override void OnPreInit(EventArgs e)
    {
       base.OnPreInit(e);
       this.MasterPageFile = "/_catalogs/masterpage/MASTER_PAGE_NAME.master";
    }

    Refer following link for a detailed code example:

    http://stackoverflow.com/questions/981685/how-to-dynamically-switch-pagelayout-and-masterpage-of-sharepoint-publishing-pag


    Leonid Lyublinski Wizard of MOSS

    Friday, March 02, 2012 8:49 PM
  • Thanks for you answer Leonid.

    Switching masterpage is easy done.

    It's the complexity of dynamic switching the page layout I'm looking for.

    I have seen the Q&A you referred to and tried to get an trail version of the produkct DualLayout to see if it's hold my standards. But unfortunate I don't receive an email with the download URL, so I have send the author an mail in hope of he can help me with the URL to try the product.

    What I hoped for, is an way to set the layout file in runtime, so it's possible to have two or more pagelayouts on same contenttype, to dynamically to switch because of some parameters.

    Thanks.

    Saturday, March 03, 2012 6:30 AM
  • LarsU_DK,

    I'd suggest to see if you can do required changes in OnPreInit event handler on PublishingLayoutPage instance. The merge between master/layout pages and the content occurs during initialization phase of the page cycle, thus dynamic changes must take place prior to that. Please post your findings afterwards.


    Leonid Lyublinski Wizard of MOSS

    Saturday, March 03, 2012 3:59 PM
  • Leonid,

    I have looked in the PublishingLayoutPage in the OnPreInit, but I don't see any possible way to change the layout file in the class or elsewhere. I have used reflector to find a solution to my problem, but I can't find out where the layout file is being set/changed. But I guess it's not just a solution easy to create, so I hope i get more time to check other solutions. I don't understand why no one else have had this problem and have a solution for it to share :)

    Monday, March 05, 2012 7:19 AM
  • Handlerfactory did the job.
    Saturday, March 10, 2012 7:37 AM
  • Handlerfactory did the job.

    Could you please to have more details on your solution?

    Thanks for sharing

    Dan


    Dan

    Tuesday, May 29, 2012 6:51 PM