powershell icon indicating copy to clipboard operation
powershell copied to clipboard

[BUG] Set-PnPPageWebPart: Cannot set images for image / image gallery web part

Open JoeAlanis opened this issue 4 years ago • 2 comments

Discussed in https://github.com/pnp/powershell/discussions/1071

Hi Team, I see that this was marked with a bug number, but I am not sure it's been acknowledged and worked on. Please disregard if it is.

Thanks in advance!

Originally posted by robi26 August 30, 2021 Hi I'm trying to add and configure an image / image gallery web part to my pages using the following code:

$imgWebPart = Add-PnPPageWebPart -Page $page -DefaultWebPartType Image -Section 1 -Column 1
$json = $imgWebPart.PropertiesJson | ConvertFrom-Json
$json.siteId = $site.Id
$json.webId = $web.Id
$json.listId = $imageList.Id
$json.uniqueId = $images[0].id
Set-PnPPageWebPart -Page $page -Identity $imgWebPart.InstanceId.Guid -PropertiesJson $(ConvertTo-Json $json)

The $json looks as follows:

{
  "imageSourceType": 0,
  "imageSource": "",
  "captionText": "",
  "altText": "",
  "linkUrl": "",
  "overlayText": "",
  "fileName": "",
  "siteId": "139f5750-2d56-4783-8568-fad2668a1dd3",
  "webId": "1f25310d-b433-4153-b50f-4e9f4c19aaca",
  "listId": "3d17631e-2cdf-4584-a572-613cc8c5ccc5",
  "uniqueId": "9658870c-6a44-4f26-9bfe-33725bb5915a",
  "imgWidth": "",
  "imgHeight": ""
}

The web part is added to the page (shown when in edit-mode) but no image is displayed. Same when trying to add an image gallery. Even getting the PropertiesJson from a manually configured web part and re-setting it with set-pnppagewebpart does not work.

I also tried to set the imageSource property to the URL of the image. Doesn't help.

Expected behavior

Images are displayed.

Thanks for any help / ideas...

JoeAlanis avatar Nov 17 '21 14:11 JoeAlanis

I have a similar problem. Is there any solution? There was an bug #1424 reported but never solved due to "No response". I've created a new issue as my problem refers to Add-PnPPageWebPart #1560

schieleingrid avatar Jan 26 '22 13:01 schieleingrid

I haven't got a working solution. I have tried to manually set the ServerProcessedContent section of the json along with the web part properties, but no luck :( . I had better luck with the image gallery, but unfortunately, it doesn't honor the setting to change the layout to Carousel. It stays in the brick type layout.

JoeAlanis avatar Feb 02 '22 21:02 JoeAlanis

hi @JoeAlanis / @schieleingrid - we have added a new Add-PnPPageImageWebpart which is available in tomorrow's nightly as well as next major version whenever that happens. This allows you to add an image webpart with certain properties like height, width, align, link URL etc .

Closing this issue now

gautamdsheth avatar Oct 01 '22 19:10 gautamdsheth