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.