Office 365 : CSWP & Display template : display custom image when no results
-
07-10-2020 - |
Question
I'm a little stuck on a problem where i'm sure you could help me :
What i want :
I want to add a Content Search Webpart to a page, which check all the items added today in a certain Image Library called BIB001. These images are rendered in a custom slider. If there is no items in the result (a.k.a no image added today), i want to show to the user/visitor, a custom image saying "there is nothing to show".
What i already have :
On office 365, I already have the CSWP and the display templates (control and item display templates) set to display the images of today in a slider. In my Control display template, i have this code :
ctx.ListDataJSONGroupsKey = "ResultTables";
var items = ctx.ListData.ResultTables[0].ResultRows;
if(items.length===0)
{
console.log("there is no image");
}
It should work. But it doesn't.
What i already tried :
In fact, after some more investigation, i've tried only to run a console.log("I'm in Control display template");
at the beginning of the divs, but i can't see a thing in my console. I deduce that when there is no item to show, O365 doesn't even enter the Control display template ! So how am i supposed to tell it that if there is no items, it has to show some custom image ?
I've seen this bunch of code in standard control displya template (like in Control_List): But I can't make it execute, because O365 doesn't execute the Control code.
<!--#_
if (ctx.ClientControl.get_shouldShowNoResultMessage())
{
_#-->
<div class="_#= noResultsClassName =#_">_#= $noResults =#_</div>
<!--#_
}
_#-->
Could you help me with that big problem of mine please?
Can you help me to discover why O365 does not enter my Control_Slider.html when there is no items given by the query?
Thanks a lot for your time, your patience and your kindness. At least thanks you to help me understand a little more how O365/SP2013 work :)