Вопрос

When running the following PowerShell code using the PnP module (Install-Module SharePointPnPPowerShellOnline):

Connect-PnPOnline -Url https://tenantname.sharepoint.com/sites/sitename -UseWebLogin
Add-PnPClientSidePageSection -Page "Home" -SectionTemplate OneColumnFullWidth -Order 0
$part = Add-PnPClientSideWebPart -Page "Home" -DefaultWebPartType Hero -Section 1 -Column 1
$strTemp = '{"id": "c4bd7b2f-7b6e-4599-8485-16504575f590", "instanceId": ... }' // JSON
Set-PnPClientSideWebPart -Page "Home" -Identity $part.InstanceId.Guid -PropertiesJson $strTemp

It displays the following error message:

Set-PnPClientSideWebPart : You cannot host this web part inside a one column full width section, only webparts that support full bleed are allowed
At line:1 char:1
+ Set-PnPClientSideWebPart -Page "Home" -Identity $part.InstanceId.Guid ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Set-PnPClientSideWebPart], Exception
    + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.ClientSidePages.SetClientSideWebPart

This code works fine when the section is set to OneColumn instead of OneColumnFullWidth. Neither Hero or Image web part is working. The removed JSON was pulled from a different SP site, and works fine on a OneColumn section.

How do you get this to work on a communication SP site for a full-width section?

Это было полезно?

Решение

A workaround is to create the Hero web part in a different section, then move the web part to the full-width section afterward:

Connect-PnPOnline -Url https://tenantname.sharepoint.com/sites/sitename -UseWebLogin
Add-PnPClientSidePageSection -Page "Home" -SectionTemplate OneColumnFullWidth -Order 0
Add-PnPClientSidePageSection -Page "Home" -SectionTemplate OneColumn -Order 1
$part = Add-PnPClientSideWebPart -Page "Home" -DefaultWebPartType Hero -Section 2 -Column 1
$strTemp = '{"id": "c4bd7b2f-7b6e-4599-8485-16504575f590", "instanceId": ... }' // JSON
Set-PnPClientSideWebPart -Page "Home" -Identity $part.InstanceId.Guid -PropertiesJson $strTemp
Set-PnPClientSidePage -Identity "Home" -LayoutType Home -Publish:$true -CommentsEnabled:$false
# MOVE THE WEB PART TO FULL-WIDTH SECTION
Move-PnPClientSideComponent -Page Home -InstanceId $part.InstanceId -Section 1
Set-PnPClientSidePage -Identity "Home" -LayoutType Home -Publish:$true -CommentsEnabled:$false
Лицензировано под: CC-BY-SA с атрибуция
Не связан с sharepoint.stackexchange
scroll top