Search code examples
powershellsharepointsharepoint-2013sharepoint-branding

Custom page layout only working on server locally


When adding and applying a custom pagelayout with PowerShell it only seems to work on the server. When I try to open the page externally I get a blank content page (masterpage does work). The site I work on is has publishing features enabled. The PowerShell code I use to apply:

$urlSiteRel = /sites/TheSiteName

$PageLayoutRelUrl = "$urlSiteRel/_catalogs/masterpage/MyPortalLayout.aspx"

# Get the Page URL
$PageName = "Portal.aspx"

# Get the Title of the Page which is going to get created
$PageTitle = "My Portal"

# Initialize the Site Object
$Site = Get-SPSite($urlSite)

# Get the Publishing Site based on the SPSite
$PubSite = New-Object Microsoft.SharePoint.Publishing.PublishingSite($Site)

# Get the SPWeb Object
$Web = Get-SPWeb $urlSite

# Initialize the PublishingWeb based on the SPWeb
$PubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($Web)

# Get the PageLayouts Installed on the Publishing Site
$Layouts = $PubSite.GetPageLayouts($False)

# Get our PageLayout
$PageLayout = $Layouts[$PageLayoutRelUrl]

# Create a new publishing page.
$Page = $PubWeb.AddPublishingPage($PageName, $PageLayout)

# Assign the Title for the Page
$Page.Title = $PageTitle

# Update the Page
$Page.Update();

# Check in the Page with Comments
$Page.CheckIn("Checkedin")

# Publish the Page With Comments
$Page.ListItem.File.Publish("Published")

Solution

  • I think i $Layouts[$PageLayoutRelUrl] you should provider web relative url for your page layout instead of server relative. In my i'm not using trailing /,

    to sum up, please try

    $PageLayoutRelUrl = "_catalogs/masterpage/MyPortalLayout.aspx"