1

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 3

2

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).

1

You could use the Managed Property SiteTitle in your display template in order to show it.

2
  • 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
    @BennySkogberg even the question is the same :)
    – Akhoy
    Commented Aug 25, 2015 at 12:45
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.