Access managed properties in Control template

Those who have worked with display templates would have worked with accessing managed properties in the item template of the Content Search Web Part (CSWP). There might be a requirement when you want to access the values of the managed properties of each result item in the control template of your CSWP rather than your item template.

The below code does exactly that:

clip_image001

a. $.each() is the jQuery loop function that is used to loop through each result returned

b. ctx.ListData.ResultTables[0].ResultRows retrieves the “RelevantResults” results from the 4 result tables available in the CSWP as shown below:

clip_image002

c. function (key, val) is the function that is going to process each search result.

d. val.EmailDate.toString(): Here only we are accessing the managed property called “EmailDate” from the variable “val” which would hold the values of all managed properties of the result item.

Advertisements

One thought on “Access managed properties in Control template

  1. ctx.ListData.ResultTables does not work in IE for me , works in Chrome. Do you have any idea about any fix for this? In IE when i debug ctx.ListData object does not show ResultTables property

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s