PortiBlog

Tiles in SharePoint Search using Display Templates

29 juni 2016

What?

Summary: this post is to show how you can use SharePoint Search and display templates to show content displayed as the famous Tiles

If you have ever created a fresh subsite in SharePoint 2013 and SharePoint Online, you must have noticed the tiles on the landing page:
Tiles_11_Default

Why?

How nice would it be if we would be able to use these tiles to show content; whether it would be a set of sites / lists / libraries / items / documents or even hyperlinks (for places in AND outside of SharePoint)? Of course there is the Promoted Links app which you can easily add from the SharePoint Store, where you can add items that can be shown in web parts as clickable tiles but when you ever have tried to promote the promoted links app to key users, you probably noticed the following downsides:

  • the web part showing these tiles is only usable within the site where the app is added...
    one of the things I love in SharePoint is the idea of having content in one location and display that content in multiple locations throughout the whole environment
    "I want to manage the content only once!"
  • the app needs a list which stores the information to assemble the tiles (Title, Background Image Location, Description, Link Location, Launch Behavior, Order)
    Tiles_21_Promoted_links_form
    another thing I love about SharePoint is the possibility show the content itself instead of creating secondary content to show the primary content
    "I want to show already existing content without creating extra content!"

How?

Now we know why we want what, let's put some energy in how we will achieve this.
First of all, it is important to know the basics of SharePoint Search and how content has crawled properties which eventually need to managed properties: Benjamin Niaulin has covered this topic countless times so please see his post Understand SharePoint Crawled and Managed properties for search.

When you understand the logic of content with properties being crawled, crawled properties being managed and managed properties being used in SharePoint Search, a useful resource is the Overview of crawled and managed properties in SharePoint Server 2013 to determine which properties are already existing with which configuration. To deep dive in the way managed properties are and could be configured, see the Guide to the search schema in SharePoint 2013 of Corey Roth.

The last thing to have some basic knowledge about is the concept of Display Templates which can be used in the Content Search Web Part as well as the Search Results Web Part to show content in a way you would like. Display templates contain HTML with Javascripting and even CSS - these are all topics I know nothing about and I managed to get this far so please continue to read =D

There are basically two possible scenarios:

  1. Content is already existing and you want it to show as Tiles on one or more pages
    A frequently used example is when you want to show a selection of subsites or a selection of pages
  2. Content may be outside of SharePoint and you want to show the hyperlinks as Tiles on one or more pages
    A frequently used example is a list of important hyperlinks to share within one or more team
    Tiles_31_subsites_example

Needless to say: a combination of 1 and 2 can be achieved in one web part as long as you can determine the correct search query. Combine this with the fact that SharePoint Search takes the permissions into account with security trimming and you can make personalized pages while maintaining one page or even one reusable web part!


Steps for both scenarios:

1. Add some "help-files"  for the display templates to a folder in the Style Library (don't forget to publish major version) in this example I added a Portiva folder to the style library so the location is ~sitecollection/Style Library/Portiva/ - this reference is important to remember

2. Add the display templates to the display template gallery so they will be available in search web parts (don't forget to publish a major version and have the right reference to the help-files) in the root of the Site Collection --> Site Settings --> Master pages and page layouts --> Display Templates --> Content Web Parts - drag&drop html file here (alternative is also possible through SharePoint Designer --> All Files --> _catalogs --> masterpage --> Display Templates --> Content Web Parts - drag&drop html file here

For Scenario 1 you can use the Content Search Web Part and configure it with the managed properties that are configured with the Retrieve setting enabled:
Tiles_42_hyperlinks_example_settings
Search Query for subsites of current site collection = contentclass:STS_Web AND Site<>{Site.URL} AND WebTemplate<>APP Path:{Site.URL}

For Scenario 2 you need to create a custom list and from my experience you can use the following existing site columns next to the default Title so no extra managed properties need to be configured: Rollup Image (PublishingRollupImage) & Description (KpiDescription) & Web Page (WebPage)
Tiles_32_subsites_example_settings
Search Query for items of the custom list = path:"https://url/Lists/LinksInTiles/"  (IsDocument:"True" OR contentclass:"STS_ListItem")

That's it! Hope this helps and gives you some inspiration to display Tiles using SharePoint Search.

Submit a comment