Forum Discussion
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.
- paulpaschaBronze Contributor
Hi Pieter,
I've seen the same thing
Thanks for submitting an issue!
paulpascha, 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
- paulpaschaBronze Contributor
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.
- paulpaschaBronze Contributor
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:
http://stackoverflow.com/questions/12962114/how-to-use-named-groups-when-performing-a-regex-replace
- paulpaschaBronze Contributor
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...