At first this seems pretty hard but there's only 3 areas you have to worry about
- Map your Managed Properties
- Do some Javascript on your value from #1
- Display some value in the HTML
For #1 locate the <mso:ManagedPropertyMapping msdt:dt="string">. If for instance you need the ListItemId of the item in question add it to the end of the list after a comma. Here's what it looks like with the single quotes escaped:
,'ListItemID':'ListItemID'
You will now have access to this like this:var itemID = $getItemValue(ctx, "ListItemID");
For #2 just stick your javascript after the <!--#_.
If you want to use jQuery include it after the
$includeLanguageScript(this.url,...
enter this:
$includeScript(this.url, "https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.0.min.js");
with jQuery that inserts into the HTML (DOM) put all your jQuery code within this:
AddPostRenderCallback(ctx, function () {
// code here
});
For #3 just insert your javascript variable like this:
<div>_#= itemID =#_</div>
Update: After doing several Display Templates that have to display custom properties I think the best approach is to simply grab the ListItemId and maybe some other fields that are OOTB. Going through the effort of creating new Managed Properties and such might not be worth it when you can simply use a REST call to get the rest of the info you need like this
Update: After doing several Display Templates that have to display custom properties I think the best approach is to simply grab the ListItemId and maybe some other fields that are OOTB. Going through the effort of creating new Managed Properties and such might not be worth it when you can simply use a REST call to get the rest of the info you need like this
$.getJSON( "REST API CALL URL", function(data) {alert( data.SOMEFIELD );})
No comments:
Post a Comment