Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sharepoint Display templates
1. SharePoint - Display Templates
Everything you need to know to get started and beyond
1
2. What are Display Templates?
Defines the visual layout of search results
HTML -> JavaScript file
Client side rendering – meaning it is your browser which renders the markup
On first call all data is included on the page itself, subsequent calls use AJAX
– CSWP can load async on first load as well
2
3. What does it do?
Uses managed properties
Uses HTML and JavaScript to display content
3
6. Web parts which use Display Templates
Search Box
Refinement (Control + Item)
Search Result
– Control
– Item
– Group (harder to change)
Content By Search
– Control
– Item
6
7. Where are the templates located?
Located in each site collection
– /_catalogs/masterpage/Display Templates
7
9. A template may be used for multiple things
Re-use template for Search Result and CSWP
9
10. What triggers a Display Template to be used?
Hard coded in web part
– Common mistake
Result Type
– Best practise
10
Display Template
Trigger Conditions
11. Best Practise for Web Part Setup
11
Web Part
Result
Source
(Scope)
Result Type
Item
Template
Control
Template
12. Web Part Query Setup
12
Pick a result source
Define the query as a
result source instead
Much easier to
change – no page
edit required
13. Include custom Script/CSS
Include custom CSS/JS in the control templates
– Executed before results are rendered
Execute JavaScript after your results are rendered
13
ctx.OnPostRender = [];
ctx.OnPostRender.push(function(){
<your code>
});
14. Mapping Crawled Properties to Managed Properties
Use RefinableXXYY – easier to locate and maintain – and give them aliases
– Decide if it should be a global property (SSA) or for a specific site collection
Best Bet implementation has a managed property which is an exception
– NoRecall
Use in templates
<mso:ManagedPropertyMapping
msdt:dt="string">'bestbetTitleOWSTEXT':'VerIT.bestbetTitleOWSTEXT','bestbetDescriptionOWSMTXT':'VerIT.
bestbetDescriptionOWSMTXT','bestbetUrlOWSTEXT':'VerIT.bestbetUrlOWSTEXT','bestbetImageUrlOWSTEXT':'Ver
IT.bestbetImageUrlOWSTEXT'</mso:ManagedPropertyMapping>
var bbTitle = $getItemValue(ctx,"bestbetTitleOWSTEXT").value;
For hover panels, be sure to include custom properties in the item template
14