3

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?

1

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 ).

enter image description here

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:

enter image description here

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 ? – Gautam Sheth May 18 '18 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.