7

I use Display Templates for rendering ContentBySearchWebPart. Nice feature, but how I can add custom properties from search results list item into Display Template?

For example, I have a template, some_listitem_template.html:

<!--#_
var line1 = $getItemValue(ctx, "Line 1");
var line2 = $getItemValue(ctx, "Line 2");
var line3 = $getItemValue(ctx, "Line 3");

for (var p in ctx.CurrentItem)
{
    console.log(p + ":" + $getItemValue(ctx, p));
}

line1.overrideValueRenderer($contentLineText);
line2.overrideValueRenderer($contentLineText);
_#-->
<div class="news-date">_#= line3 =#_</div>
<div class="news-title">
   <a href="_#= linkURL =#_" title="_#= $htmlEncode(line1.defaultValueRenderer(line1)) =#_">_#= line2 =#_</a>
</div> 

And I have Property Mapping declaration string <mso:ManagedPropertyMapping msdt:dt="string">'Link URL':'Path','Line 1':'Title','Line 2':'Description', 'Line 3':'Created'</mso:ManagedPropertyMapping>

But these properties (Description and Created) is always empty. Debug information from console.log show me that ContextItem has a pretty small collection of properties:

Rank:0 
DocId:46734
Path:http://someurl/news/Page-1.aspx
Title:Some title
FileExtension:aspx
SecondaryFileExtension:aspx
OriginalPath:somepath
PartitionId:0c37852b-34d0-418e-91c6-2ac25af4be5b5
UrlZone:1
AAMEnabledManagedProperties:AttachmentURI;deeplinks;DefaultEncodingURL;ExternalMediaURL;HierarchyUrl;OrgParentUrls;OrgUrls;OriginalPath;ParentLink;Path;PictureThumbnailURL;PictureURL;PublishingImage;recommendedfor;ServerRedirectedEmbedURL;ServerRedirectedPreviewURL;ServerRedirectedURL;SiteLogo;SitePath;SPSiteURL;UserEncodingURL
RenderTemplateId:~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Default.js
QueryRuleId:00000000-0000-0000-0000-000000000000

Suppose its because Search Configuration, but where is this place exactly?

4
  • Great question, i would love to know the answer as well - fighting with it at the moment
    – Andrey
    Commented Nov 19, 2013 at 20:34
  • I don't fully undestand how is this mechanism works eventually, but right now I'm using fields with names CommentsOWSMTXT and ArticleStartDateOWSDATE for my purposes. These fields is indexed and mapping to ordinary Article Content Type columns and Display Tempalte works just fine. Commented Dec 6, 2013 at 10:28
  • how are you deploying that display template? I had the same issue as you do, and turns out I had to specify some extra stuff in element.xml. Let me know if that's the case
    – Andrey
    Commented Dec 11, 2013 at 19:04
  • What extra stuff are you talking about? Any examples? At the moment we are not using any *.wsp packages at all. In my case it's only a client-side SharePoint development (like masterpages, styles, layouts, displaytemplates, javascript libs) using Node.js and deploy process is as simple as copying *.html files via grunt deploy. Take a look, for example generator-sp2013. Commented Dec 12, 2013 at 2:40

2 Answers 2

3

Things to check:

  1. Go to /_catalogs/masterpage and find your displaytemplate's js file. View its properties and make sure you see the mappings in question in Managed Property Mappings property.
  2. Go to Centra Admin -> Manage Service Applications -> Search Application and look at your schema - make sure that Description and Created are existing managed properties and tehy have corresponding crawled properties.
1
  • I would add a 3rd step, which would be check in the .html file. after numerous failed attempts, it just so happen to work immediately after I checked in the file. I was seeing the updated changes (saving .html saves .js automatically) but the fields were empty Commented Apr 4, 2019 at 16:34
2

One other thing to check, if you are using result types to display items:

Go to /_layouts/15/manageresulttypes.aspx?level=sitecol at the site collection level, and /_layouts/15/manageresulttypes.aspx?level=site at the site level, and click update if there is a property sync warning.

enter image description here This needs to be done every time the mappings are changed in the template

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.