Skip to content
2 min read

Duplicate Display Templates Showing up in Available Templates List

Recently I had been working on a new mechanism to deploy pre-built Content Search WebParts into new Office 365 tenant environments. The process included pre-creating a handful of display templates and then creating a Provider-hosed app to provision all the new display templates into the Master Gallery. Once I did this and used the Client Object model to create these files in the new environment, I started plugging away at building my pages and I noticed something strange. All of my deployed display templates were showing up twice in the available templates list!

Duplicates

I was bewildered! When I selected the first of the duplicates, the content search webpart would always fail. However if I selected second duplicate, my deployed display template would work just fine. So my first thought was maybe somehow the display template was duplicated in the master gallery. If the deployment was successful I should have one html and one js file created for each display template respectively. When I went to look inside my Master Gallery that is exactly what I saw!

MasterGallery

Needless to say, this left me a little stumped. When I opened up the file properties, they looked identical to the OOTB display templates from Microsoft. This lead me to believe that something with my app which deploys the files had to be the problem. Lo and behold this was exacatly the problem! 

When I was deploying the files in the Master Gallery and then updating the new list item, I had to set properties such as ContentTypeId, TargetControlType, UIVersion, etc... Well one of the properties which I thought I was supposed to update was the DisplayTemplateLevel.

DisplayTemplateCode

I have commented out the line of code which was the culprit! The issue could be a result of me only deploying out the  HTML file for my display template and having the JS file be autocreated. I think the reason that it is related is because a coworker of mine noticed something strange in the available list items. We opened up Chrome Debugging tools and inspected the available templates dropdown list and found this!

Options

The listing should only be showing the Javascript files, yet as you can see from the image...my HTML files were also being displayed. This was due to the fact that the DisplayTemplateLevel was being set on the HTML file as well as the resulting JavaScript file that was being generated.

Lesson Learned: Do not update the DisplayTemplateLevel when deploying these files into your master gallery!

Share
  
DON'T MISS!

Expert Insights from the Aerie Team

Drop us a line

Our team will be happy to answer your questions.

ADDRESS: 110 West Canal Street, Suite 201
Winooski, VT 05404

PHONE
: (813) 358-4656
HOURS: 8:00 am - 5:00 pm EST Monday to Friday
EMAIL: chanson@aerieconsulting.com