2

I've added a URL site column to my custom list. However URL isn't accessible in my display template.

I want to do something like:

var url = ctx.CurrentItem.URL;

Here's my current display template:

<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"> 
<head>
<title>My Item</title>

<!--[if gte mso 9]><xml>
<mso:CustomDocumentProperties>
<mso:TemplateHidden msdt:dt="string">0</mso:TemplateHidden>
<mso:MasterPageDescription msdt:dt="string">Displays the default result item template.</mso:MasterPageDescription>
<mso:ContentTypeId msdt:dt="string">0x0101002039C03B61C64EC4A04F5361F385106603</mso:ContentTypeId>
<mso:TargetControlType msdt:dt="string">;#SearchResults;#</mso:TargetControlType>
<mso:HtmlDesignAssociated msdt:dt="string">1</mso:HtmlDesignAssociated>
<mso:ManagedPropertyMapping msdt:dt="string">&#39;Title&#39;:&#39;Title&#39;,&#39;Path&#39;:&#39;Path&#39;,&#39;Description&#39;:&#39;Description&#39;,&#39;EditorOWSUSER&#39;:&#39;EditorOWSUSER&#39;,&#39;LastModifiedTime&#39;:&#39;LastModifiedTime&#39;,&#39;CollapsingStatus&#39;:&#39;CollapsingStatus&#39;,&#39;DocId&#39;:&#39;DocId&#39;,&#39;HitHighlightedSummary&#39;:&#39;HitHighlightedSummary&#39;,&#39;HitHighlightedProperties&#39;:&#39;HitHighlightedProperties&#39;,&#39;FileExtension&#39;:&#39;FileExtension&#39;,&#39;ViewsLifeTime&#39;:&#39;ViewsLifeTime&#39;,&#39;ParentLink&#39;:&#39;ParentLink&#39;,&#39;FileType&#39;:&#39;FileType&#39;,&#39;IsContainer&#39;:&#39;IsContainer&#39;,&#39;SecondaryFileExtension&#39;:&#39;SecondaryFileExtension&#39;,&#39;DisplayAuthor&#39;:&#39;DisplayAuthor&#39;,&#39;URL&#39;:&#39;URL&#39;</mso:ManagedPropertyMapping>
<mso:HtmlDesignConversionSucceeded msdt:dt="string">True</mso:HtmlDesignConversionSucceeded>
<mso:HtmlDesignStatusAndPreview msdt:dt="string">http://van-devmoss1/sites/ppisolutions/_catalogs/masterpage/Display Templates/Search/Item_MyItem.html, Conversion successful.</mso:HtmlDesignStatusAndPreview>
</mso:CustomDocumentProperties>
</xml><![endif]-->
</head>
<body>
    <div id="Item_MyItem">
<!--#_ 
        if(!$isNull(ctx.CurrentItem) && !$isNull(ctx.ClientControl)){ 
            console.log(ctx.CurrentItem);
            console.log(ctx.CurrentItem.Title);
            console.log(ctx.CurrentItem.Path);
            console.log(ctx.CurrentItem.URL);
            var id = ctx.ClientControl.get_nextUniqueId();
            var itemId = id + Srch.U.Ids.item;
            var hoverId = id + Srch.U.Ids.hover;
            var hoverUrl = "~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Default_HoverPanel.js";
            $setResultItem(itemId, ctx.CurrentItem);
            if(ctx.CurrentItem.IsContainer){
                ctx.CurrentItem.csr_Icon = Srch.U.getFolderIconUrl();
            }
            ctx.currentItem_ShowHoverPanelCallback = Srch.U.getShowHoverPanelCallback(itemId, hoverId, hoverUrl);
            ctx.currentItem_HideHoverPanelCallback = Srch.U.getHideHoverPanelCallback();
_#-->
            <div id="_#= $htmlEncode(itemId) =#_" name="Item" data-displaytemplate="DefaultItem" class="ms-srch-item">
                _#=ctx.RenderBody(ctx)=#_  
            </div>
<!--#_ 
        } 
_#-->
    </div>
</body>
</html>
4
  • Can you try ctx.CurrentItem.Path Nov 10, 2014 at 19:07
  • That gives me the path to the item (something.DispForm.aspx?ID=3). But it doesn't give me the value I've entered in the URL site column.
    – matt
    Nov 10, 2014 at 19:14
  • Can you post the complete code? Nov 10, 2014 at 19:52
  • Please see updated question.
    – matt
    Nov 10, 2014 at 21:24

3 Answers 3

2

Check the Managed Properties of URL from

Site Settings -> Search Schema -> Search using Managed property

Once you find the property name you need to update it in ManagedPropertyMapping tag and then access it using

ctx.CurrentItem.ManagedPropertyNameOfURL
7
  • The problem is if I search through the schema for URL I get 25 results, but none stand out as what I'm looking for.
    – matt
    Nov 10, 2014 at 23:36
  • You can use build query and try combinations till you figure out the actual property name Nov 10, 2014 at 23:37
  • Using "Build your Query" I can filter using a property called URLOWSURLH. But if I add that to my ManagedPropertMapping tag it comes out as undefined.
    – matt
    Nov 12, 2014 at 19:01
  • I can also filter my query using OWS_URL, but again if I add this to ManagedPropertMapping tag I get undefined.
    – matt
    Nov 12, 2014 at 19:15
  • 1
    I also have the same problem - the property URLOWSURLH is a mapped property and if I choose an OOTB display template like 2 Lines and set the managed property in the web part to be URLOWSURLH it shows up. However, if I create my own display template based on 2 Lines and set one of those managed properties to use URLOWSURLH I get nothing and it shows as Undefined in the debugger. What the hell is going on?
    – Tim
    Dec 17, 2014 at 17:15
1

You may want to try: ctx.CurrentItem["URL.desc"]

1

Steps Use URL Site Column in Display Template

  1. Create Source List
  2. Add URL Column
  3. Add Sample Content to List
  4. Run Search Crawl (Incremental)
  5. In Central Admin > Search Administration > Search Schema
  6. Create New Managed Property
  7. Properties (Text, Query, Search, Retrieve, and Safe)
  8. Mappings to Crawled Properties (ows_URL)
  9. Run Search Crawl (FULL)
  10. Add Content Search WP to your page and Set "Your New Managed Property Name" to the Link URL under Property Mappings Field

Source(s): This blog helped me a bit http://www.kbasrai.com/b/2014/08/25/find-items-where-url-field-contains-the-site-url

Good Luck -Schuess

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.