I am working on a content search web-part inside my SharePoint Enterprise server 2013.

Now i have the following general overview of my current sites and lists which i am trying to query inside my web part:-

  • Inside the Root site i have a list named Dept . SiteURL=http://servername/
  • Inside another sub-site I have a list named Module which have a lookup field (DeptID) referencing the Dept list. SiteURL=http://servername/Modules/
  • Now for each Module item (inside the Module list) we have a sub-site representing this module item. the sub-site url will contain the module item ID, as follow; http://servername/Modules/1 (representing module item id 1), http://servername/Modules/2 (representing module item id 2), etc..
  • Inside each Module sub-site we have a Tracking list.

Now i have added a Content Search WebPart inside my Dept list's display form; to show all the Tracking items which are related to the current Dept Item (the dept item which is being rendered inside the display form).

So inside the content search web-part i am trying to do the following:-

  1. Now by default when users click on a certain Dept item, they will be redirected to the display form. and the department ID will be inside the URL such as DispForm.aspx?ID=16..
  2. Using REST API i can query all the Modules items (inside the Module List) which have their DeptID (lookup column) = the current DeptID (for example 16 ).
  3. So in this way i will have a list of all the module items' IDs which are related to the current Dept.
  4. Then i can inside my content search web part's display template (which will mainly show all the tracking items from all the module sub-sites) to specify to only show the Tracking items which are inside a sub-site and the sub-site's url = one of the related module IDs...

Now i am not sure how i can achieve these four steps inside my display templates?


  • 1
    Sure, you can call any REST endpoint with a jQuery.$ajax( ) call, your own pure JavaScript xhr code , or learn to use the new PnPCoreJS library Microsoft developed and is about to hit version 2.0 : sharepoint.github.io/PnP-JS-Core Dec 20, 2016 at 9:15
  • @Danny'365CSI'Engelman so you mean i can write a jQuery function directly inside my display template? if so then where exactly i need to add the script inside the display templete ? second question should the script be inside the 'Control_List' or the 'Item_List' display template ? third point we calling a jQuery can i get back the results (ModuleIDs in my case) and use it inside the display template ??
    – John John
    Dec 20, 2016 at 9:44
  • 1. That's up to you as the programmer. 2. Depends on when you need it, in Control if you only need it once, in Item if each Item needs different info 3. Yes, that is the whole point of DisplayTemplates. I suggest you first learn the basics of Display Templates before you introduce the rather difficult async ajax stuff. I fear you are now trying to built a skyscraper without having built a house before. Dec 20, 2016 at 9:50
  • @Danny'365CSI'Engelman I am already familiar with display templates and i build some custom display templates before. but i always rely on the search results to show the data .. now in my scenario i need to know who i can use REST end point inside my display template..but i can not find relevant documentations regarding this..
    – John John
    Dec 20, 2016 at 10:13
  • If a developer has thorough understanding of REST and DisplayTemplates , he/she knows how to combine the two... If the developer doesn't know how to combine the two he/she has not enough understanding yet of the two individual ingredients, and shoudl dive into them one by one first. The only person I know who might actually blog about the combination is Elio Struyf: eliostruyf.com Dec 20, 2016 at 10:22

1 Answer 1


My advice is to not put your REST call inside the display template. Instead post process the search results.

Or you can use REST to search your items instead of the display template ('_api/search/query'). And then post-process those.

The reason is that every display template will call your custom JavaScript(jQuery). It’s probably not very performant, nor scalable to call a web service within every search result item.

  • now i was thinking of using a pure javascript/REST to implement this without relying on any content search web-part or display templates. but the limitations i find is that i will have many tracking lists inside the Modules sub-sites, and users will be added additional sub-sites/tracking lists ,, the only thing which these tracking lists share is the content type. so if i want to use the REST API then how i will be querying these tracking lists and merge the results, this will not be possible.... unless the search its self have an API which i am not aware of ..
    – John John
    Dec 20, 2016 at 14:17
  • so i will be querying the search API rather than the list API ??
    – John John
    Dec 20, 2016 at 14:18
  • one side note, now you said it will not be feasible to add REST calls inside display template, since the REST calls will always be executed whenever the display template is rendered.. but in my case i can create (i actually already created) a dedicated display temples for my above requirement only ...
    – John John
    Dec 20, 2016 at 14:30
  • 1
    You can use rest to query the search api. e.g: /_api/search/query?Querytext='ContentType:\"My content type\"'
    – Chris DS
    Jan 3, 2017 at 13:50
  • ok so i can query the search api,, but i am not sure how i can reference the search api call result inside my display template ??
    – John John
    Jan 7, 2017 at 16:17

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.