Skip to content

[BUG] Page templates always have layout type FullWidthImage when I use Invoke-PnPSiteTemplate #1112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 of 6 tasks
mfdezvil opened this issue Feb 21, 2025 · 2 comments
Open
1 of 6 tasks

Comments

@mfdezvil
Copy link

mfdezvil commented Feb 21, 2025

Reporting an Issue or Missing Feature

After I import a PnP Site Template with "Invoke-PnPSiteTemplate" command, which has page templates in Site Pages library with layout type "NoImage", these pages always has value "fullWidthImage".

Expected behavior

If my site template has pages with "NoImage" layout and I use Invoke-PnPSiteTemplate, it should be use value that I have defined in site template, not default ones.
Despite of that, if I use command Set-PnPPage with parameter "HeaderLayoutType", it should change page header layout type, as documentation says, to allowed values: ColorBlock, CutInShape, FullWidthImage, NoImage.

Actual behavior

I use "Invoke-PnPSiteTemplate" command with a site template which has page templates in Site Pages library with layout type "NoImage", but these pages always has value "fullWidthImage".
I try to change page layout to set value "NoImage" with command

Set-PnPPage -Identity "PageName" -HeaderLayoutType "NoImage"

but nothing changes. Page always have layout type "FullWidthImage".

I have tried to get page with Get-PnPPage and update layout value specifically:

$pageToEdit = Get-PnPPage -Identity "PageName";
$pageToEdit.PageHeader.LayoutType = "NoImage";
$pageToEdit.Save();
$pageToEdit.Publish();

but nothing changes either.

Steps to reproduce behavior

I have a PnP Site Template "siteTemplate.xml" with one Page Template that has layout type "NoImage":

<?xml version="1.0" encoding="utf-8"?> <pnp:Provisioning xmlns:pnp="http://schemas.dev.office.com/PnP/2022/09/ProvisioningSchema"> <pnp:Preferences Generator="PnP.Framework, Version=1.17.30.0, Culture=neutral, PublicKeyToken=0d501f89f11b748c" /> <pnp:Templates ID="CONTAINER-TEMPLATE-515B3B3499114765B66FF42C860F5626"> <pnp:ProvisioningTemplate ID="TEMPLATE-515B3B3499114765B66FF42C860F5626" Version="1" BaseSiteTemplate="SITEPAGEPUBLISHING#0" Scope="RootSite"> <pnp:ClientSidePages> <pnp:ClientSidePage PromoteAsNewsArticle="false" PromoteAsTemplate="true" Overwrite="true" Title="TestTemplate" ThumbnailUrl="" PageName="Templates/TestTemplate.aspx"> <pnp:Header Type="Default" LayoutType="NoImage" ShowTopicHeader="false" ShowPublishDate="false" ShowBackgroundGradient="false" TopicHeader="" AlternativeText="" Authors="[]" AuthorByLine="[]" AuthorByLineId="-1" /> </pnp:ClientSidePage> </pnp:ClientSidePages> </pnp:ProvisioningTemplate> </pnp:Templates> </pnp:Provisioning>

Then I use this command to apply site template:

Invoke-PnPSiteTemplate -Path "siteTemplate.xml";

When I get page template layout, I retrieve this value:

(Get-PnPPage -Identity "Templates/TestTemplate.aspx").PageHeader.LayoutType;

"FullWidthImage";

I try to change it with Powershell:

Set-PnPPage -Identity "Templates/TestTemplate.aspx" -HeaderLayoutType "NoImage";

Nothing changes:

(Get-PnPPage -Identity "Templates/TestTemplate.aspx").PageHeader.LayoutType;

"FullWidthImage";

Also I try to change it with commands:

$pageToEdit = Get-PnPPage -Identity "Templates/TestTemplate.aspx";
$pageToEdit.PageHeader.LayoutType = "NoImage";
$pageToEdit.Save();
$pageToEdit.Publish();

Nothing changes:

(Get-PnPPage -Identity "Templates/TestTemplate.aspx").PageHeader.LayoutType;

"FullWidthImage";

😢

What is the version of the Cmdlet module you are running?

PnP.PowerShell 2.12.0

Which operating system/environment are you running PnP PowerShell on?

  • Windows
  • Linux
  • MacOS
  • Azure Cloud Shell
  • Azure Functions
  • Other : please specify
@rachaelsingleton
Copy link

Did you figure anything out? I also am experiencing the same issue.

@mfdezvil
Copy link
Author

Did you figure anything out? I also am experiencing the same issue.

Hi @rachaelsingleton , I was investigating and I realised that bug only affects with "Invoke-PnPSiteTemplate" action. So, if you create page template with this command:

Add-PnPPage -Name "TestTemplate.aspx" -PromoteAs Template -HeaderLayoutType "NoImage"

Page template will create succesfully with provided page header, even if you want to change it later with "Set-PnPPage" command. This avoids to use "Invoke-PnPSiteTemplate" -which produces the bug, I think- and keeps code simple.

In my particular case, I need to use "Invoke-PnPSiteTemplate" because my site template contains a lot of configuration about page templates, so I have to use an ugly code workaround:

First, I get my template pages from siteTemplate XML and create them using PnP Command "Add-PnPPage":

[xml]$xmlConfig = Get-Content ("siteTemplate.xml")
$allPages = $xmlConfig.Provisioning.Templates.ProvisioningTemplate.ClientSidePages.ClientSidePage;
foreach($page in $allPages)
{
      if ($page.PageName.StartsWith("Templates/")) 
      {
          $nameTemplate = $page.PageName.replace('Templates/','');
          Add-PnPPage -Name $nameTemplate -PromoteAs Template -HeaderLayoutType $page.Header.LayoutType 
      }
}

Then, I use "Invoke-PnPSiteTemplate" to overwrite recently created template pages with desired configuration. Note: Page layout will be overwrited with "FullWidthImage" value again, but I will fix it in next step.

Invoke-PnPSiteTemplate -Path "siteTemplate.xml"

Finally, I fix all my template pages again with a loop:

foreach($page in $allPages)
{
      if ($page.PageName.StartsWith("Templates/")) 
      {
          $clientSidePage= Get-PnPClientSidePage -Identity $page.PageName;
          $clientSidePage.PageHeader.LayoutType = $page.PageHeader.LayoutType;
          $clientSidePage.save();
          $clientSidePage.Publish();
          #Alternative: you can use this command "Set-PnPPage -Identity $page.PageName -HeaderLayoutType $page.PageHeader.LayoutType" instead of above lines
      }
}

I know is an ugly code, but it was the only way I found to skip somehow this bug. I hope it will be usefull for you while someone fix PnP Framework engine for this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants