Cloud

SP2013 Search DYI Display Template

For this project, I highly recommend these tools (in a slightly sarcastic manner!):

  • A Highlighter (your mouse)
  • A pair of scissors or a copy machine (cut/copy)
  • Some glue (paste)
  • Some pieces of pre-constructed SharePoint  (good ol’ SharePoint 2013)
  • Your own paper (favorite text editor)

Today, we are going to create our own custom Hover Panel Display Template. I chose the Hover Panel for this demonstration simply because you have to do a good copy and paste job three times… and once you get the Hover Panel Display Template, then the Results Display Template follows the same model.

Let’s Craft (or something of the sort)!

Before we create our Display Template, we need to obtain some pieces from SharePoint. Go to the site settings where you are hosting your search center here: Site Settings –> Master Pages and Page Layouts –> Display Templates –> Search. You will need to download a local copy of the following files:

defaulthoverpanel

and

commonhoverpanel

After you have all of that, let’s open up Item_Default_HoverPanel.html. Here you will find the base Hover Panel markup that we will be using. In your text editor, click SAVE AS to save the file under a new filename. This way we won’t overwrite the old Item_Default_HoverPanel.html in the display template library.

2013-02-21_1330

1. Change the title here. This will be how your item is displayed when selecting a specific display template.

2. Give it a short description

3. ManagedPropertyMapping (optional): We will go over in more detail in another blog how to properly surface managed properties. In short however, for example, add this ‘ManagedProperty1’:’ManagedProperty1’ inside the tags.

4. You should change the div id to something related to your item type.

5. ctx.RenderHeader(ctx) –> For this, you’ll need parts of Item_CommonHoverPanel_Header.html.

  • In your custom Hover Panel, delete _#= ctx.RenderHeader(ctx) =#_
  • Get those scissors and glue and cut/copy the following section from Item_CommonHoverPanel_Header.html.
    • The section in grey highlighted below is what you need to copy. Between the div Item_CommonHovePanel_Header.

2013-02-21_2259

  • Paste the code you copied into the div where you removed _#= ctx.RenderHeader(ctx) =#_

2013-02-21_2319

 

6 and 7

  • Rinse and repeat for _#= ctx.RenderBody(ctx) =#_ and _#= ctx.RenderFooter(ctx) =#_
    • _#= ctx.RenderBody(ctx) =#_ goes with Item_CommonHoverPanel_Body.html
    • _#= ctx.RenderFooter(ctx) =#_ goes with Item_CommonHoverPanel_Actions.html

In the end, you should end up with a file that looks something similar to this:

Full Item Hover Panel Code:

   1: <html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"> 

   2: <head>

   3: <title>Modified Hover Panel</title>

   4:  

   5: <!--[if gte mso 9]><xml>

   6: <mso:CustomDocumentProperties>

   7: <mso:TemplateHidden msdt:dt="string">0</mso:TemplateHidden>

   8: <mso:MasterPageDescription msdt:dt="string">Displays the modified hover panel template.</mso:MasterPageDescription>

   9: <mso:ContentTypeId msdt:dt="string">0x0101002039C03B61C64EC4A04F5361F385106603</mso:ContentTypeId>

  10: <mso:TargetControlType msdt:dt="string">;#SearchHoverPanel;#</mso:TargetControlType>

  11: <mso:HtmlDesignAssociated msdt:dt="string">1</mso:HtmlDesignAssociated>

  12: <mso:ManagedPropertyMapping msdt:dt="string">'Title':'Title','Path':'Path','Description':'Description','EditorOWSUSER':'EditorOWSUSER','LastModifiedTime':'LastModifiedTime','CollapsingStatus':'CollapsingStatus','DocId':'DocId','HitHighlightedSummary':'HitHighlightedSummary','HitHighlightedProperties':'HitHighlightedProperties','FileExtension':'FileExtension','ViewsLifeTime':'ViewsLifeTime','ParentLink':'ParentLink','FileType':'FileType','IsContainer':'IsContainer','SecondaryFileExtension':'SecondaryFileExtension','DisplayAuthor':'DisplayAuthor'</mso:ManagedPropertyMapping>

  13: </mso:CustomDocumentProperties>

  14: </xml><![endif]-->

  15: </head>

  16: <body>

  17:     <div id="Item_Modified_HoverPanel">

  18: <!--#_

  19:         var i = 0;

  20:         var id = ctx.CurrentItem.csr_id;

  21:         ctx.CurrentItem.csr_ShowViewLibrary = !Srch.U.isWebPage(ctx.CurrentItem.FileExtension);

  22:         if(ctx.CurrentItem.IsContainer)

  23:         {

  24:             ctx.CurrentItem.csr_FileType = Srch.Res.ct_Folder

  25:         }

  26: 

  27:         ctx.currentItem_ShowChangedBySnippet = true;

  28: 

  29: _#-->

  30:         <div class="ms-srch-hover-innerContainer ms-srch-hover-standardSize" id="_#= $htmlEncode(id + HP.ids.inner) =#_">

  31:             <div class="ms-srch-hover-arrowBorder" id="_#= $htmlEncode(id + HP.ids.arrowBorder) =#_"></div>

  32:             <div class="ms-srch-hover-arrow" id="_#= $htmlEncode(id + HP.ids.arrow) =#_"></div>

  33:             <div class="ms-srch-hover-content" id="_#= $htmlEncode(id + HP.ids.content) =#_" data-displaytemplate="DefaultHoverPanel">

  34:                 <div id="_#= $htmlEncode(id + HP.ids.header) =#_" class="ms-srch-hover-header">

  35:                     <!-- _#= ctx.RenderHeader(ctx) =#_ -->

  36:                     <!--#_

  37:         var id = ctx.CurrentItem.csr_id;

  38:         var fileType = ctx.CurrentItem.csr_FileType;

  39:         if($isEmptyString(fileType)){

  40:             fileType = HP.GetFriendlyNameForFileType(ctx.CurrentItem);

  41:         }

  42:         var showFileIcon = Boolean(ctx.CurrentItem.csr_ShowFileIcon);

  43:         var titleCSSClass = "ms-srch-hover-title ms-dlg-heading ms-srch-ellipsis";

  44:         var maxViews = 10000;

  45: _#-->

  46:         <div>

  47:             <div class="ms-srch-hover-close">

  48:                 <a href="javascript:HP.Close()" id="_#= $htmlEncode(id + HP.ids.close) =#_" title="_#= $htmlEncode(Srch.Res.hp_Tooltip_Close) =#_">

  49:                     <img class="js-callout-closeButtonImage" src="_#= $urlHtmlEncode(GetThemedImageUrl('spcommon.png')) =#_" alt="_#= $htmlEncode(Srch.Res.hp_Tooltip_Close) =#_" />

  50:                 </a>

  51:             </div>

  52: <!--#_

  53:             if (showFileIcon) {

  54: _#-->

  55:                 <img class="ms-srch-item-icon ms-positionRelative" id="_#= $htmlEncode(id + Srch.U.Ids.icon) =#_" onload="this.style.display='inline';this.style.bottom='-5px'" src="_#= $urlHtmlEncode(Srch.U.getIconUrlByFileExtension(ctx.CurrentItem)) =#_" />

  56: <!--#_

  57:             }    

  58:             if(!$isNull(ctx.CurrentItem.ViewsLifeTime)) {

  59:                 var formattedViewsLifeTime;

  60: 

  61:                 if (ctx.CurrentItem.ViewsLifeTime > maxViews)    {

  62:                     formattedViewsLifeTime = maxViews.localeFormat("N0") + "+";  

  63:                 } 

  64:                 else {

  65:                     formattedViewsLifeTime = ctx.CurrentItem.ViewsLifeTime.localeFormat("N0"); 

  66:                 }

  67:                 var views = "";

  68:                 titleCSSClass = titleCSSClass + " ms-srch-hover-title-extraMarginForViews";

  69:                 if (ctx.CurrentItem.ViewsLifeTime === 1) {

  70:                     views = Srch.Res.hp_Views_Singular;

  71:                 } 

  72:                 else {

  73:                     views = Srch.Res.hp_Views_Plural;

  74:                 }                   

  75:                 var tooltipViewsEncoded = $htmlEncode(String.format(Srch.Res.hp_Tooltip_Views, formattedViewsLifeTime));

  76: _#-->            

  77:                 <div class="ms-srch-hover-popularity ms-metadata" title="_#= tooltipViewsEncoded =#_ ">        

  78:                     <div id="_#= $htmlEncode(id + HP.ids.viewsLifeTime) =#_"> _#= $htmlEncode(formattedViewsLifeTime) =#_ </div>

  79:                     <div> _#= $htmlEncode(views) =#_ </div>

  80:                 </div>

  81: <!--#_

  82:             }

  83:             if (!Srch.U.e(ctx.CurrentItem.Title)) {

  84: _#-->        

  85:                 <div class="_#= titleCSSClass =#_" id="_#= $htmlEncode(id + HP.ids.title) =#_"  title="_#= $htmlEncode(ctx.CurrentItem.Title) =#_">

  86:                     _#= $htmlEncode(ctx.CurrentItem.Title) =#_

  87:                 </div>

  88: <!--#_                        

  89:             }

  90: _#-->    

  91:         </div>

  92:         <div class="ms-metadata">

  93:             <div class="ms-srch-hover-filetype">

  94: <!--#_

  95:                 if (!Srch.U.e(fileType) && $isNull(ctx.CurrentItem.ServerRedirectedEmbedURL)) {

  96: _#-->

  97:                     <span id="_#= $htmlEncode(id + HP.ids.fileType) =#_">

  98:                         _#= $htmlEncode(fileType) + " " =#_

  99:                     </span>

 100: <!--#_

 101:                 }                

 102: _#-->

 103:             </div>

 104:         </div>

 105: <!--#_

 106: 

 107:     AddPostRenderCallback(ctx, function(){

 108:         if (Srch.U.e(ctx.CurrentItem.ServerRedirectedEmbedURL)){

 109:             Srch.U.logClick($get(id), "Hover");

 110:         } else {

 111:             Srch.U.logClick($get(id), "HoverWithWAC");

 112:         }

 113:     });

 114: 

 115: _#-->

 116:                 </div>

 117:                 <div id="_#= $htmlEncode(id + HP.ids.body) =#_" class="ms-srch-hover-body">

 118:                     <!-- _#= ctx.RenderBody(ctx) =#_ -->

 119:                     <!--#_

 120:         var id = ctx.CurrentItem.csr_id;

 121:         var dataShown = false;

 122:         var changedBySnippetShown = false;

 123: 

 124:         if (ctx.currentItem_ShowChangedBySnippet &&

 125:             !Srch.U.n(ctx.CurrentItem.LastModifiedTime) &&

 126:             !$isEmptyString(ctx.CurrentItem.EditorOWSUSER))

 127:         {

 128:             var changedById = id + "_ChangedBy";

 129:             var editorIdentifiers = ctx.CurrentItem.EditorOWSUSER.split(" | ");

 130:             var editorEmail = "";

 131:             if(!$isNull(editorIdentifiers[0]))

 132:             {

 133:                 editorEmail = editorIdentifiers[0];

 134:             }

 135: 

 136:             var editorDisplayName = "";

 137:             if(!$isNull(editorIdentifiers[1]))

 138:             {

 139:                 editorDisplayName = editorIdentifiers[1];

 140:             }

 141: 

 142:             AddPostRenderCallback(ctx, function()

 143:             {

 144:                 EnsureScriptFunc("clienttemplates.js", "RenderUserFieldWorker", function()

 145:                 {

 146:                     EnsureScriptFunc("sp.datetimeutil.js", "SP.DateTimeUtil.SPRelativeDateTime", function()

 147:                     {

 148:                         var renderCtx = new ContextInfo();

 149:                         renderCtx.Templates = {};

 150:                         renderCtx.Templates["Fields"] = {};

 151: 

 152:                         var field =

 153:                         {

 154:                             "FieldType" : "User",

 155:                             "DefaultRender" : "1",

 156:                             "HasUserLink" : "1",

 157:                             "Type" : "User"

 158:                         };

 159: 

 160:                         var listItem =

 161:                         {

 162:                             "id" : "",

 163:                             "title" : editorDisplayName,

 164:                             "email" : editorEmail

 165:                         };

 166: 

 167:                         var listSchema =

 168:                         {

 169:                             "EffectivePresenceEnabled" : "1",

 170:                             "PresenceAlt" : "No presence information",

 171:                             "UserDispUrl" : "/_layouts/15/userdisp.aspx"

 172:                         };

 173: 
Microsoft - The Essential Guide to Microsoft Teams End-User Engagement
The Essential Guide to Microsoft Teams End-User Engagement

We take you through 10 best practices, considerations, and suggestions that can enrich your Microsoft Teams deployment and ensure both end-user adoption and engagement.

Get the Guide

 174:                         var htmlUserPresence = RenderUserFieldWorker(renderCtx, field, listItem, listSchema);

 175:                         var convertedDate = SP.DateTimeUtil.IntlDate.createFromJsLocalDate(ctx.CurrentItem.LastModifiedTime, Srch.U.getCalendarType());

 176:                         var changedDate = convertedDate.format("d", Sys.CultureInfo.CurrentCulture.name);

 177:                         var changedTime = convertedDate.format("t", Sys.CultureInfo.CurrentCulture.name);

 178: 

 179:                         var encodedChangedBySnippet = String.format(

 180:                             $htmlEncode(Srch.Res.hp_ChangedByAuthorDate),

 181:                             htmlUserPresence,

 182:                             $htmlEncode(changedDate),

 183:                             $htmlEncode(changedTime));

 184: 

 185:                         var targetElement = document.getElementById(changedById);

 186:                         if(targetElement)

 187:                         {

 188:                             targetElement.innerHTML = encodedChangedBySnippet;

 189:                         }

 190: 

 191:                         ProcessImn();

 192:                     });

 193:                 });

 194:             });

 195: _#-->

 196:             <div class="ms-srch-hover-subTitle ms-srch-hover-text ms-srch-ellipsis" id="_#= $htmlEncode(changedById) =#_"></div>

 197: <!--#_

 198:             dataShown = true;

 199:             changedBySnippetShown = true;

 200:         }

 201: 

 202:         if(ctx.currentItem_ShowChangedBySnippet &&

 203:            !changedBySnippetShown &&

 204:            !ctx.currentItem_NeverFallbackToAuthor)

 205:         {

 206:             ctx.CurrentItem.csr_ShowLastModifiedTime = true;

 207:             ctx.CurrentItem.csr_ShowAuthors = true;

 208:         }

 209: 

 210:         if (!Srch.U.n(ctx.CurrentItem.LastModifiedTime) &&

 211:             ctx.CurrentItem.csr_ShowLastModifiedTime)

 212:         {

 213:             var lastModifiedTimeId = id + HP.ids.modifiedDate;

 214:             AddPostRenderCallback(ctx, function()

 215:             {

 216:                 Srch.U.renderFriendlyTimeIntervalString(ctx.CurrentItem.LastModifiedTime, lastModifiedTimeId);

 217:             });

 218: 

 219: _#-->

 220:             <div class="ms-srch-hover-subTitle"><h3 class="ms-soften">_#= $htmlEncode(Srch.Res.hp_LastModified) =#_</h3></div>

 221:             <div class="ms-srch-hover-text ms-srch-ellipsis" id="_#= $htmlEncode(lastModifiedTimeId) =#_"></div>

 222: <!--#_

 223:             dataShown = true;

 224:         }

 225: 

 226:         if (!$isEmptyString(ctx.CurrentItem.DisplayAuthor) &&

 227:             ctx.CurrentItem.csr_ShowAuthors)

 228:         {

 229:             var authorsLabel = $resource("hp_RecentlyEdited");

 230:             if(!$isEmptyString(ctx.CurrentItem.csr_AuthorsLabel))

 231:             {

 232:                 authorsLabel = ctx.CurrentItem.csr_AuthorsLabel;

 233:             }

 234: 

 235:             var authors = Srch.U.getArray(ctx.CurrentItem.DisplayAuthor);

 236: _#-->

 237:             <div class="ms-srch-hover-subTitle"><h3 class="ms-soften">_#= $htmlEncode(authorsLabel) =#_</h3></div>

 238:                 <div class="ms-srch-hover-text">

 239:                     _#= HP.GetAuthorsHtml(id, authors) =#_

 240:                 </div>

 241: <!--#_

 242:             dataShown = true;

 243:         }

 244: 

 245:         if(!ctx.CurrentItem.csr_DataShown && !dataShown)

 246:         {

 247: _#-->

 248:             <div class="ms-srch-hover-noContent" id="_#= $htmlEncode(id + HP.ids.noData) =#_">_#= $htmlEncode(Srch.Res.hp_NoData) =#_</div>

 249: <!--#_

 250:         }

 251: _#-->

 252:                 </div>            

 253:                 <div id="_#= $htmlEncode(id + HP.ids.actions) =#_" class="ms-srch-hover-actions">

 254:                     <!-- _#= ctx.RenderFooter(ctx) =#_ -->

 255:                     <!--#_    

 256:         var id = ctx.CurrentItem.id;   

 257:         var appAttribs = "";

 258:         if (!$isEmptyString(ctx.CurrentItem.csr_OpenApp)) { appAttribs += "openApp=\"" + $htmlEncode(ctx.CurrentItem.csr_OpenApp) + "\"" }; 

 259:         if (!$isEmptyString(ctx.CurrentItem.csr_OpenControl)) { appAttribs += " openControl=\"" + $htmlEncode(ctx.CurrentItem.csr_OpenControl) + "\"" };

 260: 

 261:         if (!Srch.U.e(ctx.CurrentItem.Path))

 262:         {

 263:             var editId = id + HP.ids.open;

 264:             var editTitle = Srch.Res.hp_Tooltip_Open;

 265:             var editText = Srch.Res.hp_Open;

 266: 

 267:             if (ctx.currentItem_IsOfficeDocument)

 268:             {

 269:                 editId = id + HP.ids.open;

 270:                 editTitle = Srch.Res.hp_Edit;

 271:                 editText = Srch.Res.hp_Edit;

 272:             }

 273:             else if (!Srch.U.e(ctx.CurrentItem.ServerRedirectedURL) && !ctx.CurrentItem.IsContainer)

 274:             {

 275:                 editId = id + HP.ids.openClient;

 276:                 editTitle = Srch.Res.hp_Tooltip_OpenInClient;

 277:                 editText = Srch.Res.hp_Edit;

 278:             }

 279: 

 280:             var editHmtl = String.format('<a clicktype="ActionEdit" id="{0}" class="ms-calloutLink ms-uppercase" href="{1}" title="{2}" {3}>{4}</a>', 

 281:                                             $htmlEncode(editId), $urlHtmlEncode(ctx.CurrentItem.Path), $htmlEncode(editTitle), appAttribs, $htmlEncode(editText));

 282: _#-->                

 283:             <div class="ms-srch-hover-action">        

 284:                 _#= editHmtl =#_                   

 285:             </div>

 286: <!--#_

 287:         }

 288:         if (!Srch.U.isSPFSKU() && ctx.CurrentItem.csr_ShowFollowLink && !$isEmptyString(ctx.CurrentItem.Path)){

 289:             var isDoc = true;

 290:             if(!$isNull(ctx.CurrentItem.csr_IsSite) && ctx.CurrentItem.csr_IsSite == true){

 291:                 isDoc = false;

 292:             }

 293: _#-->

 294:             <div class="ms-srch-hover-action">

 295:                 <a id="_#= $htmlEncode(id + HP.ids.follow) =#_" class="ms-calloutLink ms-uppercase" href="javascript:HP.Follow('_#= $scriptEncode(ctx.CurrentItem.Path) =#_', true, _#= isDoc =#_)" title="_#= $htmlEncode(Srch.Res.hp_Tooltip_Follow) =#_">

 296:                     _#= $htmlEncode(Srch.Res.hp_Follow) =#_

 297:                 </a>

 298:             </div>

 299: <!--#_

 300:         }

 301: _#-->

 302:         <div class="ms-srch-hover-action">

 303: <!--#_

 304:             var emailLink = HP.GetEmailLink(ctx.CurrentItem.Title, ctx.CurrentItem.Path, ctx.CurrentItem.csr_ClientType, ctx.CurrentItem.ServerRedirectedURL);

 305: _#-->

 306:             <a clicktype="ActionSend" id="_#= $htmlEncode(id + HP.ids.send) =#_" class="ms-calloutLink ms-uppercase" title="_#= $htmlEncode(Srch.Res.hp_Tooltip_Send) =#_" href="_#= $htmlEncode(emailLink) =#_">

 307:                 _#= $htmlEncode(Srch.Res.hp_Send) =#_

 308:             </a>

 309:         </div>

 310: <!--#_

 311:         if(!Srch.U.e(ctx.CurrentItem.ParentLink) && ctx.CurrentItem.csr_ShowViewLibrary) {

 312: _#-->

 313:             <div class="ms-srch-hover-action">

 314:                 <a clicktype="ActionViewLibrary" id="_#= $htmlEncode(id + HP.ids.parentLink) =#_" class="ms-calloutLink ms-uppercase" title="_#= $htmlEncode(Srch.Res.hp_Tooltip_ViewLibrary) =#_" href="_#= $urlHtmlEncode(ctx.CurrentItem.ParentLink) =#_">_#= $htmlEncode(Srch.Res.hp_ViewLibrary) =#_</a>

 315:             </div>

 316: <!--#_

 317:         }

 318:         if(ctx.ClientControl.get_showViewDuplicates() && !Srch.U.n(ctx.CurrentItem.CollapsingStatus) && !Srch.U.n(ctx.CurrentItem.DocId)) {

 319:             if(ctx.CurrentItem.CollapsingStatus === 1){

 320: _#-->

 321:                 <div class="ms-srch-hover-action">

 322:                     <a clicktype="ActionViewDupes" id="_#= $htmlEncode(id + HP.ids.viewDuplicates) =#_" class="ms-calloutLink ms-uppercase" title="_#= $htmlEncode(Srch.Res.hp_Tooltip_ViewDuplicates) =#_" href="javascript:HP.ViewDuplicates('_#= $scriptEncode(ctx.CurrentItem.id) =#_',_#= ctx.CurrentItem.DocId =#_)">

 323:                         _#= $htmlEncode(Srch.Res.hp_ViewDuplicates) =#_

 324:                     </a>

 325:                 </div>

 326: <!--#_

 327:             }

 328:         }

 329: _#-->

 330:                 </div>

 331:             </div> 

 332:         </div>

 333:     </div>

 334: </body>

 335: </html>

Now you have a full fledged hover panel display template! Upload it to the master page gallery and you should be able to reference it from your item display templates by changing the JavaScript in the your item Display Template.

   1: var hoverUrl = "~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Modified_HoverPanel.js";

Full Item Default Display Template Code:

   1: <html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"> 

   2: <head>

   3: <title>Modified Item Body</title>

   4:  

   5: <!--[if gte mso 9]><xml>

   6: <mso:CustomDocumentProperties>

   7: <mso:TemplateHidden msdt:dt="string">0</mso:TemplateHidden>

   8: <mso:MasterPageDescription msdt:dt="string">Modified Item Display Template</mso:MasterPageDescription>

   9: <mso:ContentTypeId msdt:dt="string">0x0101002039C03B61C64EC4A04F5361F385106603</mso:ContentTypeId>

  10: <mso:TargetControlType msdt:dt="string">;#SearchResults;#</mso:TargetControlType>

  11: <mso:HtmlDesignAssociated msdt:dt="string">1</mso:HtmlDesignAssociated>

  12: <mso:ManagedPropertyMapping msdt:dt="string">'Title':'Title','Path':'Path','Description':'Description','EditorOWSUSER':'EditorOWSUSER','LastModifiedTime':'LastModifiedTime','CollapsingStatus':'CollapsingStatus','DocId':'DocId','HitHighlightedSummary':'HitHighlightedSummary','HitHighlightedProperties':'HitHighlightedProperties','FileExtension':'FileExtension','ViewsLifeTime':'ViewsLifeTime','ParentLink':'ParentLink','FileType':'FileType','IsContainer':'IsContainer','SecondaryFileExtension':'SecondaryFileExtension','DisplayAuthor':'DisplayAuthor'</mso:ManagedPropertyMapping>

  13: </mso:CustomDocumentProperties>

  14: </xml><![endif]-->

  15: </head>

  16: <body>

  17:     <div id="Item_CommonModified_Body">

  18: <!--#_

  19:         var id = ctx.CurrentItem.csr_id;

  20:         var title = Srch.U.getHighlightedProperty(id, ctx.CurrentItem, "Title");

  21:         if ($isEmptyString(title)) {title = $htmlEncode(ctx.CurrentItem.Title)}

  22: 

  23:         var useWACUrl = !$isEmptyString(ctx.CurrentItem.ServerRedirectedURL);

  24:         if(ctx.ScriptApplicationManager && ctx.ScriptApplicationManager.states){

  25:             useWACUrl = (useWACUrl && !ctx.ScriptApplicationManager.states.openDocumentsInClient);

  26:         }

  27: 

  28:         var appAttribs = "";

  29:         if(!useWACUrl)

  30:         {

  31:             if (!$isEmptyString(ctx.CurrentItem.csr_OpenApp)) { appAttribs += "openApp=\"" + $htmlEncode(ctx.CurrentItem.csr_OpenApp) + "\"" }; 

  32:             if (!$isEmptyString(ctx.CurrentItem.csr_OpenControl)) { appAttribs += " openControl=\"" + $htmlEncode(ctx.CurrentItem.csr_OpenControl) + "\"" };

  33:         }

  34: 

  35:         var showHoverPanelCallback = ctx.currentItem_ShowHoverPanelCallback;

  36:         if (Srch.U.n(showHoverPanelCallback)) {

  37:             var itemId = id + Srch.U.Ids.item;

  38:             var hoverId = id + Srch.U.Ids.hover;

  39:             var hoverUrl = "~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Modified_HoverPanel.js";

  40:             showHoverPanelCallback = Srch.U.getShowHoverPanelCallback(itemId, hoverId, hoverUrl);

  41:         }

  42:         var displayPath = Srch.U.getHighlightedProperty(id, ctx.CurrentItem, "Path");

  43:         if ($isEmptyString(displayPath)) {displayPath = $htmlEncode(ctx.CurrentItem.Path)} 

  44:         var url = ctx.CurrentItem.csr_Path;

  45:         if($isEmptyString(url)){

  46:             if(useWACUrl)

  47:             {

  48:                 url = ctx.CurrentItem.ServerRedirectedURL;

  49:             } else {

  50:                 url = ctx.CurrentItem.Path;

  51:             }        

  52:         }

  53:         ctx.CurrentItem.csr_Path = url;

  54:         var pathLength = ctx.CurrentItem.csr_PathLength;

  55:         if(!pathLength) {pathLength = Srch.U.pathTruncationLength}

  56: 

  57:         var maxTitleLengthInChars = Srch.U.titleTruncationLength;

  58:         var termsToUse = 2;

  59:         if(ctx.CurrentItem.csr_PreviewImage != null)

  60:         {

  61:             maxTitleLengthInChars = Srch.U.titleTruncationLengthWithPreview;

  62:             termsToUse = 1;

  63:         }

  64: 

  65:         var clickType = ctx.CurrentItem.csr_ClickType;

  66:         if(!clickType) {clickType = "Result"}        

  67: _#-->                

  68:         <div id="_#= $htmlEncode(id + Srch.U.Ids.body) =#_" class="ms-srch-item-body" onclick="_#= showHoverPanelCallback =#_">

  69: <!--#_

  70:             if (!$isEmptyString(ctx.CurrentItem.csr_Icon)) {

  71: _#-->

  72:                 <div class="ms-srch-item-icon">    

  73:                     <img id="_#= $htmlEncode(id + Srch.U.Ids.icon) =#_" onload="this.style.display='inline'" src="_#= $urlHtmlEncode(ctx.CurrentItem.csr_Icon) =#_" />

  74:                 </div>

  75: <!--#_

  76:             }

  77:             var titleHtml = String.format('<a clicktype="{0}" id="{1}" href="{2}" class="ms-srch-item-link" title="{3}" onfocus="{4}" {5}>{6}</a>',

  78:                                           $htmlEncode(clickType), $htmlEncode(id + Srch.U.Ids.titleLink), $urlHtmlEncode(url), $htmlEncode(ctx.CurrentItem.Title), 

  79:                                           showHoverPanelCallback, appAttribs, Srch.U.trimTitle(title, maxTitleLengthInChars, termsToUse));

  80: _#-->       

  81:             <div id="_#= $htmlEncode(id + Srch.U.Ids.title) =#_" class="ms-srch-item-title"> 

  82:                 <h3 class="ms-srch-ellipsis">

  83:                     _#= titleHtml =#_

  84:                 </h3>

  85:             </div>

  86: <!--#_ 

  87:             if (!$isEmptyString(ctx.CurrentItem.HitHighlightedSummary)) { 

  88: _#-->

  89:                 <div id="_#= $htmlEncode(id + Srch.U.Ids.summary) =#_" class="ms-srch-item-summary">_#= Srch.U.processHHXML(ctx.CurrentItem.HitHighlightedSummary) =#_</div>

  90: <!--#_ 

  91:             }

  92:             var truncatedUrl = Srch.U.truncateHighlightedUrl(displayPath, pathLength);

  93: _#-->

  94:             <div id="_#= $htmlEncode(id + Srch.U.Ids.path) =#_" tabindex="0" class="ms-srch-item-path" title="_#= $htmlEncode(ctx.CurrentItem.Path) =#_" onblur="Srch.U.restorePath(this, '_#= $scriptEncode(truncatedUrl) =#_', '_#= $scriptEncode(ctx.CurrentItem.Path) =#_')" onclick="Srch.U.selectPath('_#= $scriptEncode(ctx.CurrentItem.Path) =#_', this)" onkeydown="Srch.U.setPath(event, this, '_#= $scriptEncode(ctx.CurrentItem.Path) =#_', '_#= $scriptEncode(truncatedUrl) =#_')" >

  95:                 _#= truncatedUrl =#_

  96:             </div>

  97:         </div>

  98: <!--#_

  99:         if (!$isEmptyString(ctx.CurrentItem.csr_PreviewImage)) 

 100:         {

 101:             var altText = Srch.Res.item_Alt_Preview;

 102:             if(!$isEmptyString(ctx.CurrentItem.csr_PreviewImageAltText)){

 103:                 altText = ctx.CurrentItem.csr_PreviewImageAltText;

 104:             }

 105: 

 106:             var onloadJS = "var container = $get('" + $scriptEncode(id + Srch.U.Ids.preview) + "'); if(container){container.style.display = 'inline-block';}" +

 107:                            "var path = $get('" + $scriptEncode(id + Srch.U.Ids.path) + "'); if (path) { Srch.U.ensureCSSClassNameExist(path, 'ms-srch-item-preview-path');}" +

 108:                            "var body = $get('" + $scriptEncode(id + Srch.U.Ids.body) + "'); if (body) { Srch.U.ensureCSSClassNameExist(body, 'ms-srch-item-summaryPreview');}";

 109: 

 110:             var previewHtml = String.format('<a clicktype="{0}" href="{1}" class="ms-srch-item-previewLink" {2}><img class="ms-srch-item-preview" src="{3}" alt="{4}" onload="{5}" /></a>', 

 111:                                             $htmlEncode(clickType), $urlHtmlEncode(url), appAttribs, $urlHtmlEncode(ctx.CurrentItem.csr_PreviewImage), $htmlEncode(altText), onloadJS);

 112: _#-->       

 113:             <div id="_#= $htmlEncode(id + Srch.U.Ids.preview) =#_"  class="ms-srch-item-previewContainer"> 

 114:                 _#= previewHtml =#_

 115:             </div>

 116: <!--#_

 117:         }

 118: _#-->

 119:     </div>

 120: </body>

 121: </html>

About the Author

More from this Author

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to the Weekly Blog Digest:

Sign Up