<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Search Nuggets &#187; display templates</title>
	<atom:link href="http://blog.comperiosearch.com/blog/tag/display-templates/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.comperiosearch.com</link>
	<description>A blog about Search as THE solution</description>
	<lastBuildDate>Mon, 13 Jun 2016 08:59:45 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.9.40</generator>
	<item>
		<title>SharePoint search display templates made easy</title>
		<link>http://blog.comperiosearch.com/blog/2014/06/23/sharepoint-search-display-templates/</link>
		<comments>http://blog.comperiosearch.com/blog/2014/06/23/sharepoint-search-display-templates/#comments</comments>
		<pubDate>Mon, 23 Jun 2014 10:49:47 +0000</pubDate>
		<dc:creator><![CDATA[Madalina Rogoz]]></dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[display templates]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[sharepoint]]></category>
		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://blog.comperiosearch.com/?p=2625</guid>
		<description><![CDATA[One of the most interesting features in SharePoint 2013 are the display templates. This blog post will describe how to customize a search display template in order to show the item created date. The display templates are located in the site collection root site, under the _catalogs/Display Templates folder. Each template has two files: the html [...]]]></description>
				<content:encoded><![CDATA[<p>One of the most interesting features in SharePoint 2013 are the display templates. This blog post will describe how to customize a search display template in order to show the item created date.</p>
<p>The display templates are located in the site collection root site, under the _catalogs/Display Templates folder. Each template has two files: the html file and a javascript file. The javascript file is the one that SharePoint uses, while the html exists in order to make it easier for us developers to create and customize the display templates. Once an html file has been modified, SharePoint generates the corresponding updated javascript file, so the process is fully automated.</p>
<p>So what are the steps involved in creating a new display template?</p>
<p>In SharePoint designer, after opening the root website, navigate to the Display Templates folder. Here, in the Search subfolder, you will find the display templates that SharePoint uses for many types of results – documents, web sites, people and others. Choose a display template as a starting point for your own, depending on the result type that you are targeting, copy it and then rename it. Once saved, you will see that SharePoint has already generated the corresponding javascript file. Modify the html file as you wish. What is left to do now is to link the template to an actual result type, so that SharePoint knows what to associate your display template to. This can be done through the interface, by navigating to Site Settings – Search Result Types.</p>
<p>Let’s take it step by step.</p>
<h3>Duplicating an existing display template</h3>
<p>Open the site collection with SharePoint designer. Navigate to the Display Templates folder under <em>_catalogs\masterpage\display templates</em>. Here you will find some Folders that SharePoint uses to group Display Templates together.</p>
<p>The Word item template is in the Search folder. Make a copy of the <em>Item_Word.html</em> and rename it to <em>ComperioItem_Word.html</em></p>
<p><img class="alignnone wp-image-2626 size-full" src="http://blog.comperiosearch.com/wp-content/uploads/2014/06/spdisptemp_01.png" alt="spdisptemp_01" width="509" height="221" /></p>
<p>Edit the file and inside you will see some html and javascript code.</p>
<p>Edit the <strong>title field</strong> so that your custom template has a different display name than the original one.</p>
<p>The <em>&lt;mso:CustomDocumentProperties&gt;</em> tag contains some properties of the template. Some important properties are:</p>
<ul>
<li><em>TargetControlType</em> – tells SharePoint what the template is used for (search results, web parts, filters)</li>
<li><em>ManagedPropertyMapping</em> &#8211; contains a list of the managed properties that are or can be used by the current template</li>
</ul>
<p>The <em>&lt;body&gt;</em> tag contains the rendering logic for the display template.</p>
<p>The template can only recognize the managed properties that are listed in the header. To use another managed property, add it here. We are using the <em>Created</em> property that displays the document created date.</p><pre class="crayon-plain-tag">&lt;mso:ManagedPropertyMapping msdt:dt="string"&gt; 
'Title':'Title','Path':'Path', [………..] , ‘Created’:’Created’ 
&lt;/mso:ManagedPropertyMapping&gt;</pre><p>Now that the template is aware of the property, you can use it by adding it to the body. Add the line below in the Body of the rendering template:</p><pre class="crayon-plain-tag">&lt;div class="ms-descriptiontext"&gt; _#= ctx.CurrentItem.Created =#_ &lt;/div&gt;</pre><p><img class="alignnone wp-image-2627 size-full" src="http://blog.comperiosearch.com/wp-content/uploads/2014/06/spdisptemp_02.png" alt="spdisptemp_02" width="649" height="99" /></p>
<h3>Mapping the display template to a result type</h3>
<p>Now we are going to manually link the display template to a result type, so that we can see that it works.</p>
<p>In order for SharePoint to use your custom template, it needs to know of it. So navigate to Site Actions – Site Settings and under Site Collection Administration choose Search Result Types. Create a New Result Type for your template like below:</p>
<ul>
<li>Choose a Name</li>
<li>Choose Microsoft Word as content to match</li>
<li>Choose your custom display template</li>
</ul>
<p><a href="http://blog.comperiosearch.com/wp-content/uploads/2014/06/spdisptemp_03.png"><img class="alignnone wp-image-2628 size-medium" src="http://blog.comperiosearch.com/wp-content/uploads/2014/06/spdisptemp_03-300x189.png" alt="spdisptemp_03" width="300" height="189" /></a></p>
<p>Now go to the results page and search for a word document. The results should display a date looking like this:</p>
<p><a href="http://blog.comperiosearch.com/wp-content/uploads/2014/06/spdisptemp_04.png"><img class="alignnone size-medium wp-image-2629" src="http://blog.comperiosearch.com/wp-content/uploads/2014/06/spdisptemp_04-300x94.png" alt="spdisptemp_04" width="300" height="94" /></a></p>
<p>We have only been scratching the surface and a lot more customization can be done here, for example formatting the date value in javascript by using a function like <em>format(&#8220;yyyy-MM-dd&#8221;) </em>on a Date object. Combined, SharePoint and javascript have (almost) endless possibilities.</p>
<p>Happy coding!</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.comperiosearch.com/blog/2014/06/23/sharepoint-search-display-templates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Instant Search in SharePoint 2013</title>
		<link>http://blog.comperiosearch.com/blog/2014/05/26/instant-search-in-sharepoint-2013/</link>
		<comments>http://blog.comperiosearch.com/blog/2014/05/26/instant-search-in-sharepoint-2013/#comments</comments>
		<pubDate>Mon, 26 May 2014 07:27:23 +0000</pubDate>
		<dc:creator><![CDATA[Erik Andreassen Perez]]></dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[display templates]]></category>
		<category><![CDATA[instant search]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[sharepoint]]></category>
		<category><![CDATA[SharePoint 2013 Search]]></category>
		<category><![CDATA[ssa]]></category>

		<guid isPermaLink="false">http://blog.comperiosearch.com/?p=2297</guid>
		<description><![CDATA[Have you been thinking about implementing instant search to your SharePoint 2013 project, but not quite sure where to start? In this blog post I will try to explain how you can easily enhance the search experience in SharePoint 2013 in a few simple steps. Instant search is widely known as «the way Google do [...]]]></description>
				<content:encoded><![CDATA[<p>Have you been thinking about implementing instant search to your SharePoint 2013 project, but not quite sure where to start? In this blog post I will try to explain how you can easily enhance the search experience in SharePoint 2013 in a few simple steps.</p>
<p>Instant search is widely known as «the way Google do it» &#8211; in fact they were the ones who started this trend and now everyone are used to it. What if you could give your SharePoint users the same experience they are already familiar with?</p>
<p>To begin with you must have in mind that instant search <strong>will</strong> produce a lot more queries and that your search performance <strong>will</strong> get worse if you have too many users hammering your SSA (Search Service Application). So, yes &#8211; there is a risk. The trade-off is high if you can increase the search experience to your users, but there’s also a risk of damaging the search experience totally if things start to go slow and people end up getting zero-hits.</p>
<p>Anyways, for the proof of concept you don’t need to think about this now :-)</p>
<p>Before moving on please check that you can meet these prerequisites:</p>
<p><strong>Prerequisites</strong></p>
<ul>
<li>Administrator Access to a SharePoint 2013 site</li>
<li>SharePoint Designer 2013 or a way of mapping your site&#8217;s directory</li>
<li>A text editor such as Sublime Text or Notepad++ (doesn&#8217;t really matter, but I recommend an editor with some code highlighting / intellisense)</li>
<li>Basic understanding of the concept regarding DisplayTemplate in SharePoint 2013 (You can read more about it <a href="http://borderingdotnet.blogspot.fi/2013/03/the-anatomy-of-sharepoint-2013-display.html">here</a> and <a href="http://msdn.microsoft.com/en-us/library/office/jj945138(v=office.15).aspx">here</a> :-) )</li>
</ul>
<p>What we are going to do is that we are simply going to create a new DisplayTemplate for the SearchBox Control based on the original DisplayTemplate and edit the OnKeyUpEvent.</p>
<p><strong>Changing the DisplayTemplate</strong></p>
<ol>
<ol>
<li>Open SharePoint Designer 2013 and open your site</li>
<li>Browse to http://SPSite/_catalogs/masterpage/Display Template/Search</li>
<li>Create a copy of the DisplayTemplate named Control_SearchBox.html and name it Control_InstantSearchBox.html and open it and edit the &lt;title&gt;-tag to something else (you’ll need it do identify the template later)</li>
<li> Go to the javascript section in the template and create a function called  doInstantSearch(clientControl, value, event) that only executes the normal query request.</li>
</ol>
</ol>
<p>It should look something like this:<script src="https://gist.github.com/38a2fd89c8d10e15ea70.js?file=InstantSearch_Example_1.js"></script></p>
<ol>
<li>Edit the searchbox-control’s ‘onkeyup’-event by replacing the attribute’s value with: ‘doInstantSearch($getClientControl(this), this.value, event);’ and save your template. Now you can go to your SearchBox web part and change the template to your new one (look for the title you set in step 3.) and test it yourself.</li>
<li>Now you have a one-to-one relationship between each key you press and query that you send to your SSA. However, as you will probably notice, the whole thing feels a little bit slow and not so smooth. This is because you are hammering your SSA and re-rendering your template each time you press a key &#8211; even if it’s not a real character &#8211; not so funny right? Let&#8217;s fix it.</li>
<li>In order to fix this we need to add a character-filter and a timeout to our function. We will get the character from the keyCode and try to match the character using a regular expression. In this example we will operate with a RegEx matching all alphanumeric-characters including special norwegian characters like «æ ø å». If the character matches it we will reset the timeout function and start over with a new 300 ms delay. When we hit a non-alphanumeric character or the delay times out we will execute the search request.</li>
</ol>
<p>This is what we end up with:<br />
<script src="https://gist.github.com/38a2fd89c8d10e15ea70.js?file=InstantSearch_Example_2.js"></script></p>
<p>And now you have an instant search with a 300 ms delay for each legal character that the user enters in the search box.</p>
<p>Try it yourself :)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.comperiosearch.com/blog/2014/05/26/instant-search-in-sharepoint-2013/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
