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.
2. Introduction – Eric Overfield
Founder and SharePoint Branding/UI Lead, PixelMill
Speaker, Teacher, Advocate
Author, SharePoint Community Organizer
Located in Davis, CA
ericoverfield.com
@EricOverfield
Order Your Copy
http://pxml.ly/zsqykd
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. 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 - pixelmill.com
5. Display Templates in a Nut Shell
JavaScript based templates for rendering content
@EricOverfield - pixelmill.com
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
7. Display Templates are Now Everywhere
Refiners
@EricOverfield - pixelmill.com
Content Search Web Part
Certain System Pages
i.e. CSWP Query Builder, Reports, eDiscovery
Search Results and Hover Panels
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 - pixelmill.com
Content Query Web Part still uses XSLT
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 - pixelmill.com
12. Finding Display Templates
/_catalogs/masterpage/Display Templates
@EricOverfield - pixelmill.com
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…
15. Creating a Custom Display Template
Copy, paste and rename only the .html file
SharePoint will handle the .js for you
@EricOverfield - pixelmill.com
Always start from an existing Display Template
Modify at least the <title /> tag
Place all custom code* after the first <div>
18. Breaking Down Control Templates
@EricOverfield - pixelmill.com
<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. Breaking Down Item Templates
@EricOverfield - pixelmill.com
<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. Custom Control and Item
Display Templates
@EricOverfield - pixelmill.com
Demo
22. Search Results and Display Templates
@EricOverfield - pixelmill.com
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
24. Debugging Display Templates
@EricOverfield - pixelmill.com
Use browser developer toolbar or Visual Studio
I prefer console.log(), or set breakpoints
Binding to Visual Studio is great for long debug sessions
27. A Quick Review
@EricOverfield - pixelmill.com
What are Display Templates
Where we use Display Templates
Types of Display Templates
How to create our own Display Templates
28. Special Thanks
Corey Roth (Outstanding session from SPC 2014)
http://pxml.ly/2DF48QX
@EricOverfield - pixelmill.com
Marc Anderson (Inspiration)
http://pxml.ly/2F6U9hH
Elio Struyf (Accordion/Tab Display Template Demo Concept)
http://pxml.ly/2KDNB3R
29. Resources
SharePoint 2013 Design Manager display templates (MSDN)
http://pxml.ly/26P96C
Ultimate Diagnostic Display Template (CSWP) – on GitHub
http://pxml.ly/A3ANNG
Display template reference in SharePoint Server 2013 (TechNet)
http://pxml.ly/2KDNNKP
4 tips for using jQuery with SharePoint Display Templates
http://pxml.ly/3ZAD2GA
10 SharePoint display template tips and tricks
http://pxml.ly/MBVWT34
The Anatomy of SharePoint 2013 Display Templates
http://pxml.ly/U8YU94X
@EricOverfield - pixelmill.com
Useful JavaScript to know when working with SharePoint Display Templates
http://pxml.ly/ZE87BNW
Demo Source files on GitHub
http://pxml.ly/cDGtygL
30. Thank You
Eric Overfield
@EricOverfield
ericoverfield.com
Order Your Copy
http://pxml.ly/zsqykd
“Pro SharePoint 2013 Branding and Responsive Web Development”
(Apress – June 12th, 2013)
http://pxml.ly/EO-SP-DisplayTemplates
Display Templates
Breaking Down
Notes de l'éditeur
Slides will be available from blog and twitter
Dev heavy with majority in demos
How may here have used the CQWP, or feel they are experts with CQWPs? Who has used Display Templates? Experts?
Will make available on blog and twitter (slideshare.net), so if you remember one of those then you can always review everything we discuss
Screenshot from http://sharepoint.microsoft.com/blog/Pages/BlogPost.aspx?pID=1041
Open SPD and find Display Template folder and show sub folders along with html and js files. Also show in browser along with Content types, properties and how to disassociate
Review .html and .js files.
Create a custom control template, update title and show how js files are managed for us. Use custom content search so after publishing, we can show custom control template.
Modify aspects of control and item templates to make magical image layout based on MixItUp
https://mixitup.kunkalabs.com/
Will show custom managed properties in item template
Post render in control template
Show search results page
Modify results control template to add own class, update webpart to link to this control template
Show panel chain from item template to hover panel
Update item template to include another managed property field (add new retrieved field)
Add new panel item template and link to this based on our result type
Change refinement panel to auto collapse all fields.
Go back to CSWP demo and open up control template
Add console.log statements
Set breakpoints
Bind to Visual Studio
Thank You!
Don’t forget to check out my blog where you can download this presentation or the recording.
Easiest way to get to the material I referenced