Has anyone figured how to add links on a quicklinks webpart on a modern page ? I've tried examining the propertiesjson output from the webpart but looks quite unclear. Thoughts?
2 Answers
The trick lies in getting the webpart JSON from a workbench page.
Go to the workbench page, https://tenant.sharepoint.com/sites/test/_layouts/15/workbench.aspx
.
On this page, configure your quick links webpart and then save it and copy the webpart data (top left ).
Store that data in a standard PS multi-line variable and then set it as PropertiesJSON of the webpart.
This is true for any modern webpart.
In the below PS script, I am adding two links, https://google.com
and https://yahoo.com
and then adding the webpart.
$jsonProps = @"
{
"controlType": 3,
"displayMode": 2,
"id": "5f6ece8b-894e-4007-9f0d-9487d2d4afa9",
"position": {
"zoneIndex": 1,
"sectionIndex": 1,
"controlIndex": 1
},
"webPartId": "c70391ea-0b10-4ee9-b2b4-006d3fcad0cd",
"webPartData": {
"id": "c70391ea-0b10-4ee9-b2b4-006d3fcad0cd",
"instanceId": "5f6ece8b-894e-4007-9f0d-9487d2d4afa9",
"title": "Quick links",
"description": "Add links to important documents and pages.",
"serverProcessedContent": {
"htmlStrings": {
},
"searchablePlainTexts": {
"title": "",
"items[0].title": "Yahoo",
"items[1].title": "Google",
"items[0].caption": "",
"items[1].caption": "",
"items[0].pictureAltText": "yahoo"
},
"imageSources": {
"items[0].pictureUrl": "",
"items[1].pictureUrl": ""
},
"links": {
"baseUrl": "https:\/\/tenant.sharepoint.com\/sites\/testSite",
"items[0].url": "https:\/\/yahoo.com",
"items[1].url": "https:\/\/google.com",
"items[0].renderInfo.linkUrl": "https:\/\/yahoo.com",
"items[1].renderInfo.linkUrl": "https:\/\/google.com"
},
"componentDependencies": {
"layoutComponentId": "abfccb4d-fcbc-4720-8bcc-6183ce66c391"
}
},
"dataVersion": "1.0",
"properties": {
"items": [
{
"id": 2,
"itemType": 2,
"progId": "",
"flags": 0,
"siteId": "00000000-0000-0000-0000-000000000000",
"webId": "00000000-0000-0000-0000-000000000000",
"listId": "",
"uniqueId": "00000000-0000-0000-0000-000000000000",
"renderInfo": {
"imageUrl": "https:\/\/s.yimg.com\/dh\/ap\/default\/130909\/y_200_a.png",
"compactImageInfo": {
"iconName": "Globe",
"color": "",
"imageUrl": "",
"forceIconSize": true
},
"backupImageUrl": "",
"iconUrl": "https:\/\/spoprod-a.akamaihd.net\/files\/sp-client-prod_2018-04-27.034\/icon_genericfile_4e26b79f.png",
"accentColor": "",
"imageFit": 2,
"forceStandardImageSize": false,
"isFetching": false
}
},
{
"id": 1,
"itemType": 2,
"progId": "",
"flags": 0,
"siteId": "00000000-0000-0000-0000-000000000000",
"webId": "00000000-0000-0000-0000-000000000000",
"listId": "",
"uniqueId": "00000000-0000-0000-0000-000000000000",
"renderInfo": {
"imageUrl": "https:\/\/spoprod-a.akamaihd.net\/files\/sp-client-prod_2018-04-27.034\/icon_link_fe14f6fb.png",
"compactImageInfo": {
"iconName": "Globe",
"color": "",
"imageUrl": "",
"forceIconSize": true
},
"backupImageUrl": "",
"iconUrl": "https:\/\/spoprod-a.akamaihd.net\/files\/sp-client-prod_2018-04-27.034\/icon_genericfile_4e26b79f.png",
"accentColor": "",
"imageFit": 0,
"forceStandardImageSize": false,
"isFetching": false
}
}
],
"isMigrated": true,
"layoutId": "CompactCard",
"shouldShowThumbnail": true,
"linkStorage": "PageLinks",
"hideWebPartWhenEmpty": true,
"dataProviderId": "QuickLinks",
"webId": "6da2e540-ec43-49b7-b95b-895f9d92f428",
"siteId": "8612321f-e57b-42c4-957f-157e1e766294"
}
}
}
"@
After that, add it on the page as :
Add-PnPClientSideWebPart -Page "TestModernSitePage1" -DefaultWebPartType QuickLinks
-WebPartProperties $jsonProps -Section 1 -Column 1 -Order 1
End result:
Here, if you check the JSON, you will find a property named, base Url, replace it with your tenant url.
-
hey @user3202981, did you try the above code ? If its working, could you please mark it as answer by ticking the checkmark besides the answer ? May 18, 2018 at 12:27
-
Nice job @Gautam Sheth ! One thing I noticed is that I had to add a web part to the zone on the target page otherwise I would get an error. I used this trick to get around the restrictions on the URL for quick links having to start with http. Client I am working with insists on using file shares and IE11 for the short term. Cheers! -Xopher– XopherFeb 10, 2020 at 17:50
Here another solution to add a Quicklins webpart with minimum data and without using complicated json :
Add-PnPClientSideWebPart -Page $page -DefaultWebPartType "QuickLinks" -WebPartProperties @{title="QuickLinks 2";items=@(@{sourceItem=@{url="https://www.google.com";itemType=2;fileExtension="";progId=""};title="Google";thumbnailType=3;id=2};@{sourceItem=@{url="https://www.youtube.com";itemType=2;fileExtension="";progId=""};title="Youtube";thumbnailType=3;id=1});hideWebPartWhenEmpty="true"}
Here the result :
This code can be improved to add and manage display options.