Using display templates, how can I display the site title next to item(s)? I don't see there is a OOTB managed property.
3 Answers
You can use the 'SPWebUrl' to get the webUrl and load the title using JSOM/REST and. Use AddPostRenderCallback method and add a unique id to the element like
var titleContainerId = id + 'webTitleContainer';
add this id to the element
<a id="_#= $htmlEncode(titleContainerId) =#_"></a>
at the bottom write a callback
AddPostRenderCallback(ctx, function () {
LoadAndExecuteSodFunction('sp.js',function(){
//code to load the title and append to element with id - $htmlEncode(titleContainerId)
});
});
The SPWebUrl may not return webUrl if you use single template with search results webpart, try to create a Result Source and Result type with the display template and make sure you check the box "Optimize for frequent use" in Result Type Screen. it worked for me once I did all these steps and and SPWebUrl started working for me after waiting for 30 mins(not sure why I need to wait).
You could use the Managed Property SiteTitle in your display template in order to show it.
-
Please don't add the exact same answer to this question, as you did on this one. Instead, try to specify your answer further to make it a better of this specific question. Thank You!– Benny Skogberg ♦Commented Aug 24, 2015 at 17:12
-
1
There is none because you Query for an Item and not the site.
You need to add extra code which extracts the site url from the Item url and query the site properties for the title.