0

I would like to present a document library on the home page (default.aspx) of a classic SPO site. What I would do with hand is to edit the page - add web part - apps - select the document library.

I exported this web part, added a few placeholders to the dynamic properties and I am able to add it to a new site, but I have difficulties with one property:

<property name="ListName" type="string">#ListID#</property>

Now, I can query the list id with

$listid = (Get-PnPList | where {$_.Title -eq $listname}).ID

and substitute the #ListID# placeholder in the xml, but isn't there any better way to achieve this, without extra rounds? Can I maybe put this in the provisioning template?

Edit: Site provisioning done like:

New-PnPWeb -Title $Title -Url $SubSiteUrl -Template $Template -InheritNavigation   #default STS#0
Connect-PnPOnline $url -Credentials $credential
Apply-PnPProvisioningTemplate -Path $template

The "Document" library is made by the default STS#0 template, I don't see, how I could get the library ID. The PnP template is almost empty.

  • in provisioning template xml, simply replace the listid with <property name="ListName" type="string">{{listid:Documents}}</property> and it will work, did you try this ? – Gautam Sheth Jun 20 '18 at 6:34
  • Hm, will check this, thanks. Is this kind of use of the engine documented? – vilmarci Jun 20 '18 at 6:36
  • yes, its documented. Here is a full list of supported tokens – Gautam Sheth Jun 20 '18 at 6:37
  • Hm, can I use the tokens in an exported webpart too? With Add-PnPWebPartToWebPartPage -ServerRelativePageUrl $page -Path $webpart -ZoneId $zone -ZoneIndex $index I get a List does not exist. error. – vilmarci Jun 20 '18 at 7:11
  • no, it doesnt work with PnPWebPartToWebPartPage command as it is a standalone commandlet and not part of provisioning engine – Gautam Sheth Jun 20 '18 at 7:15
3

You can use the {{listid:ListName}} token instead of hard-coding the GUID.

When you use this token , the provisioning engine will fix the placeholder with the actual value of the List ID.

For example, if your list/document library name is Documents, use {{listid:Documents}}. Put the below line of code in your template xml file and then PnP will fix it for you:

<property name="ListName" type="string">{{listid:Documents}}</property>

Reference - Provisioning Engine tokens

1

This is the approach I use. The problem with SP Online and remote APIs is that you have no access to a strongly-typed XsltListView webpart object, so you're stuck importing an XML-based web part and swapping out the placeholders as you've done.

I don't know what your provisioning process is like, but the ones I use are typically fully automated WebJobs and the placeholder approach is pretty solid once the process is set up.

  • The process is still work in progress. My real problem is not with the placeholders. I know most of these in advance, so I can replace them in the template. But at the time of the provisioning, the list ID is not known, so I cannot fill it before I start the process. Instead, I need to go to the provisioned site, read it the id on the fly, manipulate my local file, and go back to site. – vilmarci Jun 18 '18 at 17:01
  • So, if the provisioned site is provisioned via code, you should be able to grab that ID in the same process. Instead of manipulating a local file, read the file along with the tokens into a string, and do the token replacement on the string in memory. – Derek Gusoff Jun 18 '18 at 19:10
  • I added the way I do the provisioning now to the question. – vilmarci Jun 20 '18 at 6:28

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.