Can I use more than one master page on a sharepoint site?

折月煮酒 提交于 2019-12-23 12:31:04

问题


I have been asked to modify a home page to a completely new design, all other pages will remain exactly the same.

I am a little green when it comes to sharepoint. I have created the masterpage, however when i choose set as default master page or set as customer masterpage it changes for the entire site. I would only like to change the home page.

The only option I have come across at this point would seem to be Detach from page layout which would not be ideal as the remainder of the site may be pushed into this new skin


回答1:


Programmatically changing the masterpage for this particular page is the only option as nigel says.

You can create a custom page layout for the homepage and then set the masterpage on the pre-init as shown below:

public class MyPageLayout:PublishingLayoutPage 
{ 
    protected override void OnPreInit(EventArgs e) 
    { 
        base.OnPreInit(e); 
        this.MasterPageFile = "~/_catalogs/masterpage/mynewmasterpage.master";                    
    } 
} 



回答2:


SharePoint Publishing pages inherit from the Microsoft.SharePoint.Publishing.PublishingLayoutPage class, which sets the master page programmatically to the site defined custom master page. There is no way to override this behaviour other than to do so through code yourself.



来源:https://stackoverflow.com/questions/11621877/can-i-use-more-than-one-master-page-on-a-sharepoint-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!