In my previous post, I showed how to include AngularJS to your display templates. In this part I will talk about how to extend the templates so that the document icon and “line 2” property (which is not provided by default) can be added. To provide these new values (icon and line 2) to your template, it is best to create your own dataset.
Creating our own dataset
To create our own dataset, we will loop over the results that were retrieved from the search query.
|
|
As you can see in the code I pass through the current row to process. This is needed in order be able to use the $getItemValue function which can retrieve the managed property by the slot name defined in the ManagedPropertyMapping property.
The complete code block for this looks like this:
|
|
The $getItemValue function uses the current item and the ManagedPropertyMapping data to retrieve the value for the referenced managed property.
Note: this.DisplayTemplateData.ManagedPropertyMapping is automatically created in the item display template and contains the property mappings that are configured in the CSWP.
Updating the template
Now that the new dataset has been created with your additional information, you could add these values to the template in the control display template.
The whole template now looks like this:
|
|
As you can see, you can also use the properties that have been added by the $getItemValue function. Like for instance to check if a value is empty in combination with the ngShow or ngHide directives to show or hide an element.
The new template results in the following output:
With a second line mapping set, the result looks like this:
Download
The templates for this post can be downloaded here: AngularJS Templates (CSWP).
What’s next?
In the next part I will show how you could almost eliminate the item display template, so that everything could be done from within the control display template.