After looking at the Search Results control templates, and attempting to remove pieces of the code to trim down the file to contain on the minimum amount to render an item template. Is there a good example of what is required for the control template to render properly?

My goal is to render the custom Item Template below, and add some custom logic to the control template for handling query parameters passed in.

How can I detect when no results or a null value is being returned, and execute a separate JavaScript function?

<div id="Item_CommonItem_Body">
    var id = ctx.CurrentItem.Id;
    var legacyItemId = ctx.CurrentItem.LegacyItemId;
    var listUrl = ctx.CurrentItem.ListUrl;
    var listItemId = ctx.CurrentItem.ListItemId;
    var listId = ctx.CurrentItem.ListId;
    var siteId = ctx.CurrentItem.SiteId;
    var webId = ctx.CurrentItem.WebId;
    var title = ctx.CurrentItem.Title;
    var parentLink = ctx.CurrentItem.ParentLink;
    var spsite = ctx.CurrentItem.SPSiteUrl;
    var contentType = ctx.CurrentItem.ContentType;
    var action = "/_layouts/15/CopyUtil.aspx?Use=id&Action=dispform";
    var completeLink = String.format('<a href="{0}{1}&itemId={2}&listId=
    {3}&siteId={4}&webId={5}">{6} </a>', $htmlEncode(spsite), action, listItemId,
    htmlEncode(listId), $htmlEncode(siteId), $htmlEncode(webId), title);


    <div><span><h1>Unique Item Results</h1></span></div>
        <li>Title: _#= title =#_</li>
        <li>Legacy ID: _#= legacyItemId =#_</li>
                    <li>List URL: _#= listUrl =#_</li>
        <li>List Item ID: _#= listItemId =#_</li>
        <li>List ID: _#= listId =#_</li>
        <li>Site ID: _#= siteId =#_</li>
        <li>Web ID: _#= webId =#_</li>
        <li>Parent Link: _#= parentLink =#_</li>
        <li>Completed URL: _#= completeLink =#_ </li>
        <li>SPSite _#= spsite =#_</li>
        <li>Content Type _#= contentType =#_</li>                           



  • If you mean when no items are returned at all, then you need to edit the control display template, not the item display template. The control template has a section for when there are no results.
    – wjervis
    Apr 18, 2014 at 13:54
  • made some updates to my original question. Is there a good example of a minimal control template? i'm trying to trim it down as much as possible.
    – Jason
    Apr 18, 2014 at 22:10
  • Sorry, I've not modified a control template yet. I'd say experiment, and just remove stuff until it breaks :/
    – wjervis
    Apr 19, 2014 at 1:49

1 Answer 1


You can change the control template, but remember that all of the display templates will be changed as a result. I talk about this relationship in my SPC14 session on Display Templates and Query Rules. The Control Template, Group Template and Item Templates work in concert to create the presentation that you see on the page. This is true for Search Results, Refinement and Content By Search. A single Display Template has no knowledge of "Zero Results" because if there are no results... there is no display template.

For your solution to work you will have to implement at a minimum a custom control and item template.

  • After watching your sessions, and a bit of experimentation I was able to get a solution working. Tapping into the functions the Search Control Template provides was the key piece.
    – Jason
    May 3, 2014 at 14:26
  • Great! Happy that helped! May 5, 2014 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.