Boost Productivity with SharePoint Display Templates

default post thumbnails

Reusable is a word that I have grown to love when working with SharePoint. Often in the past, I’d have to change how something looks like in SharePoint simply to improve the user experience. The problem was I’d have to rebuild it every time I’d switch list or library and even site collections. Thankfully, since SharePoint 2013’s release and Office 365, Microsoft has introduced Display Templates that allow me to do just that.

The idea of a SharePoint Display Template, in short, is a reusable design that works with Search Results. Since the new SharePoint allows you to leverage Search to find what you need and display it on a page, having these reusable designs make it very practical. In fact, I love them so much I’ve already built a few and made them available for download:

But this time, I wanted to build something that has the popular “Tiles” look. I’ll be honest I am not a fan of this design concept, but it’s what’s trending right. Essentially, I want to put these squares or rectangles to show less information on the page, but when I click I’d want to expand the details on a full page.

SharePoint Overlay Display Template

Learning SharePoint Search and Display Templates

Learn SharePoint Display Templates

This is the time, or place, to go in depth on SharePoint Search or Display Templates, but it’s important to note some of the basics. From my perspective, if you do not yet understand, or grasp, Search, Crawled Properties, Managed Properties, Control Display Templates and Item Display Templates then start there before continuing.

If it helps, I’ve done a short video that covers all of this quickly and more importantly links to many valuable resources to learn more: Leverage SharePoint Search

What I Learned Building SharePoint Display Templates

Building SharePoint Display Templates

I won’t take the credit; I love SharePoint Display Templates but I am far from what you call an expert on the subject. And I am still learning every day.

At the end of the day, I need my SharePoint to be used by our users and I want it to make me look good and be proud of what I delivered. That’s why I find myself often finding already built designs on the internet and converting them to Display Templates to be reused with SharePoint Search.

But for that, I’ve had help from many developers including Elio Struyf whom I consider to be excellent in building these. Here are a few things I learned:

  • Display Template can be built once to work with both the Search Results and Content Search Web Parts by modifying the “TargetControlType” setting in the template.
  • You’re going to hate working with MDS (Minimal Download Strategy) as it doesn’t actually reload the page all the time. In turn most of your customizations could break if not properly planned for it. You’ll want to use RegisterSOD and RegisterSODDep to call your scripts correctly.
  • RegisterSODDep is your best friend when loading multiple scripts that need to be loaded in the right order.
  • Your Item Display Template needs to start with a DIV that will not be displayed when rendered, it just needs to be there.
  • To show text written in HTML fields such as the “Body” column of an announcements list, you’ll need to use STSHtmlDecode(nameofproperty.value) to display it correctly.
  • You can make your Search Query “Refresh” without having the user reload the page.
  • Elio Struyf knows all the answers.

And I am sure there are many more tips to be given, but at the moment those are the ones that jump to mind as I wouldn’t want you to fall in the same traps as I did.

Building my SharePoint Display Template

How to Build SharePoint Display Templates

Well, I’ve gotten used to this by now. The trick is to find a design and understand what’s going on within it. Figure out what will get repeated as new Search results are shown and what stays as part of the global design of the results or the container. Then, I split things into the Control and Item Display Template.

This time I was inspired by a beautiful design to show the weather. Of course I have no interest in showing the weather in SharePoint, despite it being one of the most requested features somehow. No I liked the full page overlay style presented and thought it could be interesting for us in SharePoint. There have been a few times where I would have loved to show something full page while in SharePoint.

The hardest part in building this design was loading the scripts needed in the right order, I needed jQuery then FitText followed by BoxGrid. And I am sure there is an easier way to do this design, but I wanted the challenge.

However, once that was done it was pretty easy and straight forward. And I’ll take those whenever I can with SharePoint.

First I looked at the overall layout of the squares and rectangles on the page. These would usually show the “Title” Managed Property so I set it to that. The colors and sizes are controlled in the CSS file so it took me very little effort to get it the way I wanted.

In fact, feel free to adjust that to fit your design standards, if you’re feeling adventurous you could even make it work with the Theming Engine in SharePoint.

Then I had to modify the Overlay part of the design or what shows up full page once you click on the item. Because at the moment, it was still showing clouds and the weather for the week.

So I removed all of the fields and instead put my Managed Properties or placeholders if you will.

Here is what my Control Display Template looks like:

And my Item Display Template:

What You Should Know Before You Download the SharePoint Display Template

Download SharePoint Display Templates

Though the template works both for the Search Results and Content Search Web Part, the nature of the design makes it a lot friendlier to the Content Search. Generally speaking, you’ll want to be easily able to modify the text that shows up on the right hand side.

What I have done is separated the layout into two rectangles.

On the left hand side, you have the big title and below it the author. On the right hand side, you have three place holders or “Lines” that you can add a Managed Property to.

So either you modify the Display Template or you use the Content Search to make it work with your content. I do recommend you adapt the design to fit your branding and colors as well as the context of your page. Maybe you’ll want just squares and no rectangles.

I can see this design be useful when you need to show a lot of information, but not necessarily take up the space on the page for it unless the user clicks on it. News, Contacts, Pictures, Events… I see a lot of applications for it. How do you plan to use it?

Download all my files to get started on your design!

What did you think of this article?

Recommended by our team

Getting started is easy

Try ShareGate free for 15 days. No credit card required.

Hosts 1

LIVE VIRTUAL EVENT RISE UP: Ignite your M365 tenant migration playbook