I'm creating a custom page layout starting from the Article Page layout, which is associated by default to the master page v4.master. I want now associate this web page with a custom master page of my own. How to do it?
All page layouts use CustomMasterUrl of SPWeb (web site), thus you need to create your own implementation of PageLayout class where you redefine the master page accordingly to you requirements. You can follow the link for more details - http://blog.pixelmill.com/821/sharepoint-2010-assign-a-unique-masterpage-to-a-page-layout-in-a-publishing-portal/.
Otherwise, you can use 2 or more sites, each for specific Page Layout you are working and change CustomMasterUrl for each of them as required. Thus you'll have 2 site for example, Events and News with custom master pages and page layouts
In SharePoint designer, Set your master page as custom master page and add\edit MasterPageFile="~masterurl/custom.master" to the page directive as:
<%@ Page language="C#" MasterPageFile="~masterurl/custom.master" Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=188.8.131.52,Culture=neutral,PublicKeyToken=71e9bce111e9429c" meta:webpartpageexpansion="full" meta:progid="SharePoint.WebPartPage.Document" %>
1How can we implement this same process from the .html master page?– klewisJun 23, 2016 at 22:02
In order to change the page layout to custom master page, you will have to go to Site Actions ->Site Settings -> Look and Feel -> Master Page. Select the custom master page that you need to apply and select check box to inherit it to sub sites (if needed).
When this is done, all the page layouts(custom or OOTB), will run with the custom master page you have selected.
We need to understand here that the master page contains the page layout and not the other way around. So changing the master page will force all page layouts in the site to inherit the master page properties. And as @default has suggested above, there are ways to customize this if you really need.
This is a 2007 (ans 2010 applicable) article about changing the page layout dynamically on the file on that base of a page layout parameter. To obtain this we have to dig into the code and:
- Create a new class inheriting the PublishingPageLayout class
- Make this class override the master page retrieving behavior in the OnPreInit() event as required, by applying the specific master page
- Compile and put the assembly in the GAC
- Update the web.config to make SharePoint recognize our new assembly
- Set in our aspx page layout the property Inherits to our new Class
I've now ascertained that achieve this from just SharePoint Designer or the UI interface is not possible :(
If somebody doesn't want to create custom master page through the SharePoint Designer, you can follow the steps described in the article - SharePoint: How to create a custom master page - to create a ghostable copy of a built-in master page and get a full access to the Controls-collection due to subclussing.