Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Breaking Down Display Templates in SharePoint 2013


Published on

SharePoint 2013 utilizes search for everything, which is great! But what do you do when you want to customize results? XSLT like we used in the past? Please say no! Along with a huge improvement in search, SharePoint 2013 introduces Display Template to allow us to format results using technologies we already know including HTML and JavaScript.

In this class, we see how SharePoint 2013 uses display templates to render data produced by the Content Search, Search Results, Refinement Web Parts and more. We will look at common out-of-the-box display templates and where they are used. We will then tear a few of these displaytemplates apart and see how they tick, thus giving us the knowledge and power to create interfaces that rival the best websites out there. Display what you want, how you want it.

Published in: Design
  • Be the first to comment

Breaking Down Display Templates in SharePoint 2013

  1. 1. Eric Overfield SharePoint Advocate and Enthusiast PixelMill Display Templates Breaking Down
  2. 2. Introduction – Eric Overfield  Founder and SharePoint Branding/UI Lead, PixelMill  Speaker, Teacher, Advocate  Author, SharePoint Community Organizer  Located in Davis, CA @EricOverfield Order Your Copy Co-author: “Pro SharePoint 2013 Branding and Responsive Web Development” (Apress – June 12th, 2013) Co-author: “Black Magic Solutions for White Hat SharePoint” (August, 2013)
  3. 3. What You Will Learn  What are Display Templates  Where we use Display Templates  Types of Display Templates  How to create our own Display Templates @EricOverfield -
  4. 4. What are Display Templates @EricOverfield -
  5. 5. Display Templates in a Nut Shell  JavaScript based templates for rendering content @EricOverfield -  Based on Client Side Rendering (CSR)  HTML/JS rendering occurs at client side, not server side  Replaces the need for XSLT!  We work with HTML files, SharePoint handles most JS  SharePoint 2013 / SharePoint Online rendering engine
  6. 6. @EricOverfield - Where we use Display Templates
  7. 7. Display Templates are Now Everywhere  Refiners @EricOverfield -  Content Search Web Part  Certain System Pages  i.e. CSWP Query Builder, Reports, eDiscovery  Search Results and Hover Panels
  8. 8. @EricOverfield -
  9. 9. Display Template Alternatives?  XSLT still available for server side rendering  Must be set by exporting a Content Search Webpart  Set “AlwaysRenderOnServer” property to true  Sample XSLT can be found in: /_catalogs/masterpage/Display Templates/Server Style Sheets @EricOverfield -  Content Query Web Part still uses XSLT
  10. 10. @EricOverfield - Types of Display Templates
  11. 11. Control Templates and Item Templates  Control Templates (Similar to ContentQueryMain.xsl)  Used once per query, i.e. a general wrapper  Item Templates (Similar to ItemStyle.xsl)  Used once per result @EricOverfield -
  12. 12. Finding Display Templates  /_catalogs/masterpage/Display Templates @EricOverfield -  Stored in Master Page Gallery  Custom Display Template may be stored anywhere in MPG  Just have to properly set Content Types and Properties  Each Display Template includes a .html and a .js file  Only customize the .html file  Unless you choose to live dangerously…
  13. 13. Finding Display Templates @EricOverfield - Demo
  14. 14. Create Our Own Display Templates @EricOverfield -
  15. 15. Creating a Custom Display Template  Copy, paste and rename only the .html file  SharePoint will handle the .js for you @EricOverfield -  Always start from an existing Display Template  Modify at least the <title /> tag  Place all custom code* after the first <div>
  16. 16. Creating a Custom Display Template @EricOverfield - Demo
  17. 17. Display Template Components @EricOverfield -
  18. 18. Breaking Down Control Templates @EricOverfield -  <html>  <title /> (“name” of display template)  <body>  <div> (only place custom code after first div)  Include scripts / links to custom CSS  Additional pre-rendering JavaScript including post render binding  AddPostRenderCallback() or ctx.OnPostRender.push()  Finally your custom display code (HTML and JavaScript)
  19. 19. Breaking Down Item Templates @EricOverfield -  <html>  <title /> (“name” of display template)  <mso:ManagedPropertyMapping /> ‘JS Reference Name’{Display Name}:’Manager Property list’; i.e. 'Picture URL'{Picture URL}:'PublishingImage;PictureURL;'  <body>  <div> (only place custom code after first div)  Additional pre-rendering JavaScript  Finally your custom item display code (HTML and JavaScript)
  20. 20. Custom Control and Item Display Templates @EricOverfield - Demo
  21. 21. Search Results and Display Templates @EricOverfield -
  22. 22. Search Results and Display Templates @EricOverfield -  Display Templates used for  Refinement panels  Search Input control  Search results and result types  Hover panels  With results types, set specific item templates per item type
  23. 23. Search Results, Hover Panels, Refinement Panels and Display Templates @EricOverfield - Demo
  24. 24. Debugging Display Templates @EricOverfield -  Use browser developer toolbar or Visual Studio  I prefer console.log(), or set breakpoints  Binding to Visual Studio is great for long debug sessions
  25. 25. Debugging Display Templates @EricOverfield - Demo
  26. 26. Important JavaScript Reference @EricOverfield -  AddPostRenderCallback(ctx, function () {});  $getItemValue(ctx, "JS Reference Name");  $includeScript(this.url, "~sitecollection/…/?.js");  $includeCSS(this.url, "~sitecollection/…/?.css");  ctx.ClientControl.get_numberOfItems(); (per page)  ctx.DataProvider.get_totalRows(); (total rows)  $isNull(object), $isEmptyString(string)
  27. 27. A Quick Review @EricOverfield -  What are Display Templates  Where we use Display Templates  Types of Display Templates  How to create our own Display Templates
  28. 28. Special Thanks Corey Roth (Outstanding session from SPC 2014) @EricOverfield - Marc Anderson (Inspiration) Elio Struyf (Accordion/Tab Display Template Demo Concept)
  29. 29. Resources SharePoint 2013 Design Manager display templates (MSDN) Ultimate Diagnostic Display Template (CSWP) – on GitHub Display template reference in SharePoint Server 2013 (TechNet) 4 tips for using jQuery with SharePoint Display Templates 10 SharePoint display template tips and tricks The Anatomy of SharePoint 2013 Display Templates @EricOverfield - Useful JavaScript to know when working with SharePoint Display Templates Demo Source files on GitHub
  30. 30. Thank You Eric Overfield @EricOverfield Order Your Copy “Pro SharePoint 2013 Branding and Responsive Web Development” (Apress – June 12th, 2013) Display Templates Breaking Down