In a current project, I needed to add a quick links webpart to a new page in the site.

Note that if the page hasn’t been edited previously, the entire default contents of the page will be deleted.

Add-PnPClientSidePageSection -Page "Home" -SectionTemplate TwoColumnLeft 
if ($column.Links1) {
    Add-PnPClientSideWebPart -Page "Home" -DefaultWebPartType "QuickLinks"  -WebPartProperties $jsonProps -Section 1 -Column 1
}
else {
    write-host "Blank Links"$column.URL
    Add-PnPClientSideWebPart -Page "Home" -DefaultWebPartType "QuickLinks" -section 1 -Column 1 -WebPartProperties $jsonPropsGridBlankInitial
}

Add-PnPClientSideWebPart -Page "Home" -DefaultWebPartType "QuickLinks" -section 1 -Column 2 -WebPartProperties @jsonPropsListBlankInitial
set-pnpclientsidepage -Identity $pagename -Publish:$true 

Add-PnPClientSidePageSection -Page "Home" -SectionTemplate TwoColumnLeft 

The code above creates a new section on the page ‘Home.aspx’ on the connected site. The enumeration for the -SectionTemplate parameter are:

  • OneColumn
  • OneColumnFullWidth
  • TwoColumn
  • TwoColumnLeft
  • TwoColumnRight
  • ThreeColumn

  Add-PnPClientSideWebPart -Page "Home" -DefaultWebPartType "QuickLinks" -section 1 -Column 1 -WebPartProperties $jsonPropsGridBlankInitial

This code adds the Quick Links webpart to the page. You can change th properties of the webpart by passing the -WebPartProperties value. This is a simple Json doc, an example of which is below.

$jsonPropsGridBlankInitial = @'
   {
      "controlType":3,
      "displayMode":2,
      "id":"adc3b147-7f6e-41ef-be53-ec9a5381d200",
      "position":{
         "zoneIndex":1,
         "sectionIndex":1,
         "controlIndex":1
      },
      "webPartId":"c70391ea-0b10-4ee9-b2b4-006d3fcad0cd",
      "webPartData":{
         "id":"c70391ea-0b10-4ee9-b2b4-006d3fcad0cd",
         "instanceId":"adc3b147-7f6e-41ef-be53-ec9a5381d200",
         "title":"Quick links",
         "description":"Add links to important documents and pages.",
         "serverProcessedContent":{
            "htmlStrings":{

            },
            "searchablePlainTexts":{
               "title":""
            },
            "imageSources":{

            },
            "links":{
               "baseUrl":"https://#####.sharepoint.com/"
            },
            "componentDependencies":{
               "layoutComponentId":"706e33c8-af37-4e7b-9d22-6e5694d92a6f"
            }
         },
         "dataVersion":"2.1",
         "properties":{
            "items":[

            ],
            "isMigrated":true,
            "layoutId":"Grid",
            "shouldShowThumbnail":true,
            "buttonLayoutOptions":{
               "showDescription":false,
               "buttonTreatment":2,
               "iconPositionType":2,
               "textAlignmentVertical":2,
               "textAlignmentHorizontal":2,
               "linesOfText":2
            },
            "listLayoutOptions":{
               "showDescription":false,
               "showIcon":true
            },
            "waffleLayoutOptions":{
               "iconSize":1,
               "onlyShowThumbnail":false
            },
            "hideWebPartWhenEmpty":true,
            "dataProviderId":"QuickLinks",
            "webId":"18b335b9-3fcc-4163-96de-4cdd42920396",
            "siteId":"53e95d8f-16b4-4f9f-af8b-1ae96be919ea"
         }
      },
      "emphasis":{

      },
      "reservedHeight":204,
      "reservedWidth":736
   }
'@

 "layoutId":"CompactCard",

The layoutid property above can be changed to ‘Grid’.


In a future post, I’ll show you how to update the Json doc above to add items to the QuickLinks webpart.