pnpframework icon indicating copy to clipboard operation
pnpframework copied to clipboard

Get-PnPSiteTemplate with Pages handler ignoring centered text in Text Web Part

Open acksoft opened this issue 3 years ago • 1 comments

Reporting an Issue or Missing Feature

When extracting a PnP template from a site using the Pages handler, Text web parts on the page with centered text are not provisioned from the resulting template as centered.

Expected behavior

The page I have built has a 1 column section with a single Text web part. That text is set to 36px, Bold and Centered image On the published page is renders like this: image I expect that when I extract the page, it will create a template that will render just like this.

Actual behavior

After extracting the published page to a PnP template using the Pages handler, the generated XML looks like this: <pnp:CanvasControl WebPartType="Text" ControlId="1f099f01-352d-498b-a528-47670cec5800" Order="1" Column="1"> <pnp:CanvasControlProperties> <pnp:CanvasControlProperty Key="Text" Value="&lt;span class=&quot;fontColorThemeDarkAlt&quot;&gt;&lt;span class=&quot;fontSizeXxLargePlus&quot;&gt;&lt;strong&gt;Our News Corner&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;" /> </pnp:CanvasControlProperties> After applying the template to a different site collection, the page renders like this (with the text misaligned to the left): image When I "inspect" the page in the browser, the HTML is this: image It looks like the extraction provisioning code is ignoring the 'style="text-align:center"' that should be in the paragraph (<p>) for the page to render as desired.

Steps to reproduce behavior

As described above:

  1. Create a Modern SharePoint page with a single column section
  2. Add a text web part, add text, highlight the text, format it as centered, publish the page
  3. Call Get-PnPSiteTemplate in a script using the Pages handler
  4. Apply the resulting template to a new page

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

PnP.PowerShell 1.11.0

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

  • [X] Windows

If you can suggest a workaround or some manual tweaking to the generated XML after-the-fact to get the desired result, that will be fine. But I do not seem to have any way to access the <p> tag to add the required attribute to make the text be centered when the page renders. The generated XML only lets me edit the <span> tags inside the paragraph. Thanks in advance.

acksoft avatar Oct 13 '22 21:10 acksoft

hey just so you know, and for anyone who might find this - a workaround i discovered was just editing the value tag to wrap the strong tag in another paragraph with piped in text-align style of center.

<pnp:CanvasControlProperty Key="Text" Value="&lt;p style=&quot;text-align: center;&quot;&gt;&lt;strong&gt;On Budget&lt;/strong&gt;&lt;br&gt;🟢 ​​​​​​​$&lt;strong&gt;&amp;lt;&amp;gt;&lt;/strong&gt; (12%)&lt;/p&gt;" />

benwharg avatar May 29 '23 15:05 benwharg