Today in one of my new tenants I got the following errors in my search result web part:
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.
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.
SharePains is not just any blog run by a Microsoft MVP. Have you ever used Try-Catch in Power Automate? The original post about Try-Catch in Power Automate can still be found on this site, https://sharepains.com/2018/02/07/try-catch-finally-in-power-automate-flow/
Or have you ever used the Pieter’s method to avoid variables and speed up your flows? https://sharepains.com/2020/03/11/pieters-method-for-advanced-in-flows/
You can contact me using contact@sharepains.com
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.
SharePains is not just any blog run by a Microsoft MVP. Have you ever used Try-Catch in Power Automate? The original post about Try-Catch in Power Automate can still be found on this site, https://sharepains.com/2018/02/07/try-catch-finally-in-power-automate-flow/
Or have you ever used the Pieter’s method to avoid variables and speed up your flows? https://sharepains.com/2020/03/11/pieters-method-for-advanced-in-flows/
You can contact me using contact@sharepains.com