Friday, March 02, 2012 7:01 AM
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.
- Edited by Lars Ulriksen - SharePoint Architect Friday, March 02, 2012 7:03 AM Spelling error
Friday, March 02, 2012 8:49 PM
You can try the following steps:Refer following link for a detailed code example:
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)
this.MasterPageFile = "/_catalogs/masterpage/MASTER_PAGE_NAME.master";
Leonid Lyublinski Wizard of MOSS
Saturday, March 03, 2012 6:30 AM
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.
Saturday, March 03, 2012 3:59 PM
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
Monday, March 05, 2012 7:19 AM
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 :)
Saturday, March 10, 2012 7:37 AMHandlerfactory did the job.
- Marked As Answer by Lars Ulriksen - SharePoint Architect Saturday, March 10, 2012 7:37 AM
Tuesday, May 29, 2012 6:51 PM
Handlerfactory did the job.
Could you please to have more details on your solution?
Thanks for sharing