Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top