Monday 10 March 2014

SharePoint Custom Webpart properties for Content Search webpart

SharePoint Custom Webpart properties for Content Search webpart
Open SharePoint site
Site Settings
Master pages and page layouts
Display Templates
Search
Now download any existing template .html file
Ex:Item_TwoLines
Find below tag
<mso:ManagedPropertyMapping msdt:dt="string">'Link URL'{Link URL}:'Path','Line 1'{Line 1}:'Title','Line 2'{Line 2}:'','FileExtension','SecondaryFileExtension'</mso:ManagedPropertyMapping>
Add below tag after 'Line 2'{Line 2}:'',
'MyCustom Property'{MyCustom Property}:'',
Now the code will be..
<mso:ManagedPropertyMapping msdt:dt="string">'Link URL'{Link URL}:'Path','Line 1'{Line 1}:'Title','Line 2'{Line 2}:'','MyCustom Property'{MyCustom Property}:'','FileExtension','SecondaryFileExtension'</mso:ManagedPropertyMapping>
Add below line after :var encodedId = $htmlEncode(ctx.ClientControl.get_nextUniqueId() + "_2lines_");
var MyCustomProperty=$getItemValue(ctx, "MyCustom Property").managedPropertyName;
You will get your value in MyCustomProperty.
Rename html file and upload to same location.
Add Content Search webpart, edit web part properties
Change Item template
Select your new template
Click on Property mapping
Click Change property mapping.
You will find: MyCustom Property
Give some value in MyCustom Property, text box.
Save
Now your value will be available in
var MyCustomProperty=$getItemValue(ctx, "MyCustom Property").managedPropertyName;