Displaytemplate Urls in PnP templates


I just upgraded to the latest PnP PowerShell release ( Feb 2017) exporting my template gives me template that includes:

<property name="ItemTemplateId" type="string">{site}</property>


When I manually export the web part in sharepoint I get:

<property name="ItemTemplateId" type="string">~sitecollection/_catalogs/masterpage/Display Templates/Search/ItemScheme.js</property>


So it looks like urls are replaced with tokens incorrectly. Has anyone else seen the same. This is qutie a breaking issue, if I'm not doing anything wrong.



8 Replies

Hi Pieter,


I've seen the same thing


Thanks for submitting an issue!

@Paul Pascha, thank you for confirming.


Other than manually updating all the templates have you found any good workarounds? This is quite critical, which in my opinion would need a rerelease of the February release

I agree this is a serious issue in case your site provisioning solution relies on Get-PnPProvisioningTemplate functionality. I don't have an immediate workaround other than manually fixing your templates. 


I'll take some time later today to look at the PnP source code in order to find the bug. If I find something I'll comment in your submitted issue, or maybe fix it myself and do a pull request.

I took a quick look and I'm pretty sure the issue is caused by one of the following lines from ObjectPageContents.cs in OfficeDevPnP.Core


//some webparts already contains the site URL using ~sitecollection token (i.e: CQWP) 
xml = Regex.Replace(xml, "\"~sitecollection/(.)*\"", "\"{site}\"", RegexOptions.IgnoreCase);
xml = Regex.Replace(xml, "'~sitecollection/(.)*'", "'{site}'", RegexOptions.IgnoreCase);
xml = Regex.Replace(xml, ">~sitecollection/(.)*<", ">{site}<", RegexOptions.IgnoreCase);


I also commented this in your submitted issue...


Interestingly enough these lines were added in an attempt to fix another issue you've submitted earlier :)


I guess we should use named groups in the regEx replace as described here:


I don't understand issue #754 enough in order to be able to think of a good fix.


If I understand correctly CQWP uses the ~sitecollection token internally and it's exported together with your template. The current PnP code is trying to replace it with {site}. Honestly this doesn't make sense to me. The ~sitecollection token is recognized by CQWP (and other WebParts using it) so when importing (applying your template) the ~sitecollection token should still be included. Can you elaborate on this?


I've just submitted a pull request which undoes the changes made for issue #754. That should fix #1066 but #754 probably needs to be reopened now...

Hi @Paul Pascha,


The orignal issue had something to do with the location of the links wihtin the CQWP.


So imagine that you take a tempalate from




and apply this to




then the url is not correct.


There should be a token that holds the url of the web so that both  ~sitecollection/subsite/subsubsite and ~sitecollection/subsite are referred to as {web}

Ah thanks! I understand the issue now... I will give this further thought to see if I can come up with a new fix