Wednesday, December 9, 2015

My stance on modifying the out of the box display templates

My colleague Petter had a request from a customer to open search results in a new window/tab instead of the same one. So he conferred the braintrust at Puzzlepart on which approach he should go for.

One answers was to modify the control template and loop though all links using JavaScript and add the target=”_blank” attribute. Another to hook in a custom action to which registered a javascript which filtered on click events and did the same modification sort of.

Personally I went against what I always preach which is to never modify the OOB display templates. The customer in this case was using the oob templates, and all the oob item templates through inception reference Item_CommonItem_Body.html/js. We’re talking around 30 result types, referencing some oob template which again reference Item_CommonItem_Body.

To me modifying one line in that file to open the item in a new tab/window had the least complexity. Creating or modifying a custom control template would possibly have required reconfiguration of X pages in the search center. The custom action would have solved it all, but a solution hidden away of sorts.

When is it not ok to modify the OOB templates then?

Most modifications I come across involve adding a new managed property into the template to be displayed. Try this with an OOB template and you fail pure and simple. It just doesn’t work as you won’t be able to Update the result type binding to include your custom managed properties. For this scenario you must create a copy and tie it to your own result type.

And this is where we usually start at Puzzlepart. We have custom templates from the get-go and ready configurations for the 30 result types to be replaced. Petter’s customer already had a search solution up and running when he came in to make it rock, but rolling new display templates were not in scope.

So…. should you or should you not modify the OOB display templates? As a general rule, don’t do it, but if you know what you are doing and know the reasons why, there are scenarios which justify this. Another is to edit the default refiner template and turn on refiner counts.

And as my colleague Tarjei pointed out, if you do change the oob ones, remember that you might miss out on some awesome cool changes coming in a CU near you... or not ;-) - the reason being you have ghosted the files so it won't use possible awesomeness deployed in the 15 hive - or not ;-)

1 comment:

  1. You won this discussion for sure. Sometimes you just gotta do it!