Wednesday, November 20, 2013

How to Customize Back and Next Navigation Links in SharePoint 2013 Display Template

Ever wanted to customize the Back and Next navigation links in the SharePoint 2013 Display Template? Well, look no further. Grab your favorite beverage, and pull up your favorite playlist on Spotify, and follow the steps below to implement custom navigation links in SharePointland.

  1. Login to your favorite SharePoint 2013 Publishing site and head over to the ‘Site Settings’ page. Under the ‘Web Designer Galleries’ section, click on the ‘Master pages and page layouts’ link. Yes, the name of the link is a bit misleading. The new SharePoint 2013 display templates reside in the same neighborhood as SharePoint’s cornerstone artifacts, master pages and page layouts. Once in the master page gallery, click on the ‘Display Templates’ link. And then click on the ‘Content Web Parts’ link as shown below.
  2. The ‘Control_ListWithPaging’ template files below render the default Back and Next navigation links.
  3. Download a copy of the Control_ListWithPaging.html file. Give it a different name (example: RightpointControl_ListWithPaging.html). Edit the value in the <title> tag as shown below. Enter a descriptive title. This is the title that will be displayed in the ‘Control’ dropdown list in the Content Search web part.
  4. Continue to edit the file as follows.
    • Add the following variables. These variables reference the path where your custom back and next navigation link images are stored. In the code below, I am referencing a path in the SharePoint 15 hive. Your mileage may vary, therefore add the path corresponding to the location where the images reside in your environment.

      var nextLinkUrl = "/_layouts/15/images/Rightpoint/navigation/next.png";
      var backLinkUrl = "/_layouts/15/images/Rightpoint/navigation/back.png";
    • Add the following image tag to render the ‘back’ navigation link.

      <img alt="_#= $htmlEncode(firstPage.title) =#_" src="_#= backLinkUrl =#_">
    • Add the following image tag to render the ‘next’ navigation link.

      <img alt="_#= $htmlEncode(lastPage.title) =#_" src="_#= nextLinkUrl =#_"
    • Shown below is a screenshot showing the display template with the above edits:
  5. Upload the new display template back to the ‘Content Web Parts’ folder. Or you can also deploy the display template via a Feature (if it is part of a larger SharePoint custom solution).
  6. Publish the template as a major version.
  7. Your new display template containing your custom ‘back’ and ‘next’ navigation links is now ready for use as shown below in the Content Search web part.

Here are some excellent resources on SharePoint 2013 display templates for your reading pleasure. Enjoy!

Configure Display Templates for the Content Search web part

SharePoint 2013 Design Manager display templates