Office 365 – SharePoint – Display Error: The display template had an error.

 Today in one of my new tenants I got the following errors in my search result web part:

Sorry, something went wrong.

SHOW DETAILS HIDE DETAILS
When I opened up the error I got the following details:
Display Error: The display template had an error. You can correct it by fixing the template or by changing the display template used in either the Web Part properties or Result Types.
Template ‘~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_StaffDirectory.js’ not found or has syntax errors. (LoadTemplate: ~sitecollection/_catalogs/masterpage/Display Templates/Search/Group_Default.js)
There was no error anywhere pointing me towards the problem other than the above. I’m sure that in an on-premises version of SharePoint the ULS logs would have been great help. But  I’m on Office 365.
Quite a few errors are given within the SharePoint interface however in this case all I could do is remove sections of my display template and figure out which line caused the problem.
In this case I was using a variable in my has_uEmail

<!–#_
if(has_uEmail  == true) {
_#–>

_#= uEmail =#_

<!–#_
}
_#–>

Somehow one of the code merges had gone slightly wrong and I missed out the following line:

var has_uEmail = !$isEmptyString(ctx.CurrentItem.WorkEmail);

So using a variable that hasn’t been defined is causing SharePoint on Office 365 not to compile the html version of the display template into a JavaScript version of the same.


Discover more from SharePains

Subscribe to get the latest posts sent to your email.

Avatar of Pieter Veenstra

Is your business still running on paper trails, sprawling Excel files, or ageing Access databases? There's a better way — and I can show you exactly what it looks like. I'm the Technical Director of Vantage 365, a Microsoft solutions consultancy working with clients across the UK, the Netherlands, and worldwide. For over 30 years I've been turning messy, manual business processes into clean, automated systems that save time, reduce errors, and give teams the visibility they need to make better decisions. You can contact me using contact@sharepains.com

Related Posts

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from SharePains

Subscribe now to keep reading and get access to the full archive.

Continue reading