2

I am using SharePoint 2013. I have created a new search page. On this page you see the search result webpart and the refiner webpart etc. I have selected the search result page layout. Now I have cloned the default item search display template. I give it another name and upload it in the gallery:

Item_Voorraadbeheer.html
Item_Voorraadbeheer_HoverPanel.html

In the settings of my search result property I have selected this custom search display template and it works. I can see my custom logic. But I see in my display template this code:

_#=ctx.RenderBody(ctx)=#_

I would like to clone also the logic begind this method. How can I clone the OOTB body ? See also the red marked area what I mean with the OOTB body of each item.

enter image description here

  • Please check avnibhatt.wordpress.com/2014/04/30/… Hope it helps!!! – 404 Apr 30 '14 at 9:42
  • thank you for the fast answer, but this is not the correct answer. I would like to reuse the logic behind the RenderBody function. So I would like to clone it and customize it. – Ola Apr 30 '14 at 10:11
  • Thats what is does. Check the Item template portion. It is customized – 404 Apr 30 '14 at 10:18
  • I know I can customize the Item_Voorraadbeheer.html. I did it already. But where is the logic behind the function ctx.RenderBody(ctx)? I dont want to rebuild it. I would like to clone the logic inside of it and customize it. I give you an example. You see now OOTB the Title as first result (see also red marked area in printscreen). I would like to remove the "Title" and add my custom column, for example "CompanyName". All other stuff I would like to let it like how it is now OOTB. – Ola Apr 30 '14 at 10:26
4

Body render is defined in another display template, look for "Item_CommonItem_Body.html"

2

That #=ctx.RenderBody(ctx)=# just renders Item_CommonItem_Body.html So the idea is that you have some common managed properties you want to show for all search result types and you add those in Item_CommonItem_Body.

The specific managed properties for a result type you want to add to Item_NewResultType.html

1

While you could create a new Render Body method, usually for a new Display Template you would just add the fields that you wish to see in your result to the Display Templates Managed Property Mapping and then add the fields from the context object to the page. You could go find the Render Body function in the base SharePoint *.js files, but I really don't think it will provide much additional help, usually you just perform the rendering in your Display Template.

  • Thanks, does someone know which js file I need to look? – Ola May 5 '14 at 7:53
  • For Display Templates, use the HTML files, not the JS. If you are looking for Render Body, I think that is in Search.j's or SearchUI.js. – Matthew McDermott May 5 '14 at 12:39
1

In addition to the previous answers, take a look at this article https://medium.com/@frankchen2016/apply-custom-logic-for-all-display-templates-a0100ec7beeb It shows how you create your copy of Item_CommonItem_Body.html and specify the modified template URL in the webpart definition. That way you will have a custom copy just for your specific search results web parts and leave the standard one intact.

  • This is the correct direction & the right answer to @Ola where he wanted to have his own OOB template's clone – Anand Jun 27 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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