none
Custom display template for search

    Question

  • HI 

    I have Created a custom Item Template as shown below.I want to map this with my custom result type but it is not working

    <html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"> 
    <head>
    <title>News Item</title>
    
    <!--[if gte mso 9]><xml>
    <mso:CustomDocumentProperties>
    <mso:TemplateHidden msdt:dt="string">0</mso:TemplateHidden>
    <mso:MasterPageDescription msdt:dt="string">$Resources:Microsoft.Office.Server.Search,DisplayTemplateDescription_SearchDefaultItem</mso:MasterPageDescription>
    <mso:ContentTypeId msdt:dt="string">0x0101002039C03B61C64EC4A04F5361F385106603</mso:ContentTypeId>
    <mso:TargetControlType msdt:dt="string">;#SearchResults;#</mso:TargetControlType>
    <mso:HtmlDesignAssociated msdt:dt="string">1</mso:HtmlDesignAssociated>
    <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','SEDWMPNewsPublishDate':'SEDWMPNewsPublishDate','DisplayAuthor':'DisplayAuthor1','SiteTitle':'SiteTitle'</mso:ManagedPropertyMapping>
    <mso:HtmlDesignConversionSucceeded msdt:dt="string">True</mso:HtmlDesignConversionSucceeded>
    <mso:CrawlerXSLFile msdt:dt="string"></mso:CrawlerXSLFile>
    <mso:HtmlDesignPreviewUrl msdt:dt="string"></mso:HtmlDesignPreviewUrl>
    </mso:CustomDocumentProperties>
    </xml><![endif]-->
    </head>
    <body>
        <div id="StoraEnso_Item_Default">
    <!--#_ 
            if(!$isNull(ctx.CurrentItem) && !$isNull(ctx.ClientControl)){
                var id = ctx.ClientControl.get_nextUniqueId();
                var itemId = id + Srch.U.Ids.item;
    			var hoverId = id + Srch.U.Ids.hover;
    			var hoverUrl = "~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Default_HoverPanel.js";
                $setResultItem(itemId, ctx.CurrentItem);
    			if(ctx.CurrentItem.IsContainer){
    				ctx.CurrentItem.csr_Icon = Srch.U.getFolderIconUrl();
    			}
    			ctx.currentItem_ShowHoverPanelCallback = Srch.U.getShowHoverPanelCallback(itemId, hoverId, hoverUrl);
                ctx.currentItem_HideHoverPanelCallback = Srch.U.getHideHoverPanelCallback();
    _#-->
                <div id="_#= $htmlEncode(itemId) =#_" name="SEItem" data-displaytemplate="StoraEnsoDefaultItem" class="ms-srch-item" onmouseover="_#= ctx.currentItem_ShowHoverPanelCallback =#_" onmouseout="_#= ctx.currentItem_HideHoverPanelCallback =#_">
    				<h2 class="heading"><a href="_#= ctx.CurrentItem.Path =#_">_#= ctx.CurrentItem.Title =#_</a></h2>
    				  <div id="_#= $htmlEncode(hoverId) =#_" class="ms-srch-hover-outerContainer"></div>
    											<p>_#= Srch.U.processHHXML(ctx.CurrentItem.HitHighlightedSummary) =#_</p>
    											<div class="footer">
    											
    												<dl class="desc">
    													<dt>SiteTitle</dt> _#= ctx.CurrentItem.SEDWMPNewsPublishDate =#_
    													<dd><a class="status" href="#">_#= ctx.CurrentItem.SiteTitle =#_</a></dd>
    													<dt>Author</dt>
    													<dd><a class="status" href="#">_#= ctx.CurrentItem.DisplayAuthor =#_</a></dd>
    												</dl>
    											</div>
                  
                </div>
    <!--#_ 
            } 
    _#-->
        </div>
    </body>
    </html>

    If you see in "managedPropertyMapping" I have added a new property "SEDWMPNewsPublishDate" and when I use in my html I am not getting the value.

    I checked with fiddler and I found that This property is not getting mapped. Json object does return this property.However  this property has value. I have tested with content search webpart nad my code also.it returns value.

    Can anyone let me know is there any issue in the above rendering template code 

    On update to this, I was using resultscript webpart on the page to display data and I have created custom result type to modify the display.What I found that when I add the custom properties which I need, on result script webpart  using as follows 

     scriptWebPart.SelectedPropertiesJson = "[\"SEDWMPNewsPublishDate\",\"SEDWMPIntroduction\"]"

    and save the changes then I start getting the value of my custom properties.

    I don't know how the result type works in accordance with display templates and when does it gets applied on the search data.If anyone is aware please let me know.

    If I can't use the display templates with custom properties then what is the use of ManagedPropertyMapping on display templates.Can anyone please make me understand?

    • Edited by agarwal Thursday, January 03, 2013 10:14 AM More findings
    Thursday, January 03, 2013 8:53 AM

All replies

  • On an Update to this what I found was that Once the result type is created and after that if you modify the display template like  adding new managed property then those will not appear in display template.

    What happens is that When result type is created then it stores all the properties from the specified js file.Hence when display template is updated then result type doesn't map the new managed property so whenevr display template is updated especially with new managed property  then corresponding result type should also be updated if exist, to appear.

    Now the display template is working

    Thursday, January 03, 2013 1:04 PM
  • So what to do in this case? 

    What changes you had made to fix this issue? 

    Monday, May 06, 2013 8:28 PM
  • hi

    what is your issue? If you can explain then I can help you better however what I understand You are using custom result type to apply your custom display template.

    If you are creating the result type programmatically then you have to map the managed property from display template to result type progrmmatically. Following url may help you

    http://dev.net.ua/blogs/ivanbilokon/archive/2012/11/22/11389.aspx

    If you are creating result type using UI then after updating the display template goto result type and edit and click save again .It will Update its property

    Thursday, May 09, 2013 4:33 AM
  • After uploading the display template if i do any changes after some time its not reflecting in the display template results. What i understood is the Java Script file is not getting updated when i make changes in the html file. 


    Thursday, May 09, 2013 5:13 AM
  • You need to update the js file also.You can upload the js file also.In js file you have a column "ManagedPropertyMapping" this denotes which managed property should come for item in search.

    For uploading the js file you can use as follows under module

     <File Path="ModSearchDisplayTemplates\x.js" Url="x.js" Type="GhostableInLibrary">
          <Property Name="Title" Value="xjs" />
          <Property Name="MasterPageDescription" Value="$Resources:Microsoft.Office.Server.Search,DisplayTemplateDescription_SearchDefaultItem" />
          <Property Name="ContentType" Value="$Resources:TemplateContentType_Code_Name" />
          <Property Name="DisplayTemplateLevel" Value="Item" />
          <Property Name="TemplateHidden" Value="0" />
          <Property Name="TargetControlType" Value=";#SearchResults;#" />
          <Property Name="HtmlDesignLockedFile" Value="TRUE" />
          <Property Name="ManagedPropertyMapping" Value="'Title':'Title','Path':'Path','Description':'Description','EditorOWSUSER':'EditorOWSUSER','LastModifiedTime':'LastModifiedTime','CollapsingStatus':'CollapsingStatus','DocId':'DocId','FileExtension':'FileExtension','ParentLink':'ParentLink','FileType':'FileType','IsContainer':'IsContainer','SEDWMPNewsPublishDate00':'SEDWMPNewsPublishDate00','SEDWMPIntroduction':'SEDWMPIntroduction','SEDWMPNewsIsSticky':'SEDWMPNewsIsSticky','SEDWMPNewsPostThreadId':'SEDWMPNewsPostThreadId'"/>
        </File>

    Thursday, May 09, 2013 6:05 AM
  • I can do this then its a double work i think

    As per Microsoft we are not suppose to create the related java script file manually right? 

    Thursday, May 09, 2013 3:41 PM
  • ya that is fine but when you package your solution then you need to package the js file also because when you upload html file using "Module" element then the event will not fire and js file will not get generated.so for some scenario you need to have the js file.

    For this what  you can do is that upload the html file from UI, downlaod the generated js file, and acoordingly modify it and then you can upload it.

    Otherwise if the js file is not getitng updated itself when you upload the html file using UI then there can be issue in your sitecollection/webapplication/environment anywhere.For this you need to verify one by one

    Friday, May 10, 2013 4:18 AM
  • This is because of three reasons

    1) If the JavaScript file is not updated / sync with the HTML display template file 

    2) In the properties of the display template files if the managed property not mapped 

    Properties

    3) If SP 2013 is not installed properly 

    I verfied these parameter and fixed then it started working

    • Proposed as answer by Joseph Velliah Wednesday, May 22, 2013 8:02 PM
    Wednesday, May 22, 2013 8:01 PM
  • Agarwal,

    Does your  SiteTitle managed property have data in it? I've been trying to do something similar but my property is not returned in the ctx.CurrentItem and I have also checked that the property is marked as "Retrievable"

    This is something that we used to have in SP2010 but it appears to work differently in 2013.

    Many thanks

    Wednesday, May 07, 2014 5:58 PM