2

I found the following function overrideValueRenderer inside our custom display temple, as follow:-

    <mso:ManagedPropertyMapping msdt:dt="string">'Link URL':'Path'</mso:ManagedPropertyMapping>

<body>
    <div id="TwoLines">
<!--#_
// Give up your names for the properties in the following array
var linkURL = $getItemValue(ctx, "Link URL");
linkURL.overrideValueRenderer($urlHtmlEncode);

now i am using this variable to build a <a> link, as follow:-

String.format("<a href='{0}' class='ms-listlink'>{1}</a>", linkURL, property) 

But i am not sure what is the real purpose of the following function .overrideValueRenderer($urlHtmlEncode) because i try rendering the following value inside my display templete :-

 _#= linkURL =#_ 

And i have noted that this value will always be the same regardless if i remove the linkURL.overrideValueRenderer($urlHtmlEncode); or i keep it.

For example i will always get this value for an _#= linkURL =#_ , regardless of removing the linkURL.overrideValueRenderer($urlHtmlEncode); or i keeping it:-

http://servername/sites/deptname/Lists/Discussion/test $£'

so seems the value of the url is not url-encoded,, So I am not sure what is the effect/purpose of the overrideValueRenderer function inside my display template ? logically the linkURL.overrideValueRenderer($urlHtmlEncode); should url encode the linkURL value,, but when i render the linkURL value i will get url that is not url encoded .. is this correct ?

1

The overrideValueRenderer method will override value retrieved from the managed property.

For example, if the value of managed property of type text has large number of characters , so it will get trimmed and the value displayed would be (upto 90 characters + ellipsis).

In case, the managed property is giving us date/time value, this function will apply some logic on the value, format it , clean it and transform the value into a presentable date format.

In other cases, like this one urlHtmlEncode, it should give you back the trimmed, formatted and encoded url value. I think you can remove the line containing overrideValueRenderer in this case since encoding is not getting applied.

overrideValueRenderer is defined in the Search.Controls.debug.js and Search.Controls.js of the 15 hive. You can take look at its implementation in those js files.

Also check the below screenshot from a book, Pro SharePoint 2013 Branding and Responsive Web Development , which gives us some idea about what is happening here. Unfortunately, i cant find any official documentation for the same.

enter image description here

OverrideValueRenderer

Display Templates and wrong date formatting

  • thanks for the reply. now you mentioned "_ I think you can remove the line containing overrideValueRenderer in this case since encoding is not getting applied._" but i do not think that this function which is defined in almost every display temple i have seen, does not have any effect... it should url encode the value,, but it is not doing so ... so is it a bug or i need to render the linkURL value in certain way to get it url encoded.. – john Gu Nov 5 '16 at 0:55
  • can you advice on my reply please? – john Gu Nov 7 '16 at 12:40
  • Sorry for late replies. No it's not a bug, it looks like the url is already encoded (see above image in answer for desc) . Hence its not getting encoded again in the override function. However, if you think that the encoding is not working you can encode it using the OOTB function as: $urlHtmlEncode(linkURL); – Gautam Sheth Nov 7 '16 at 12:53
  • so you mean the url is already encoded , without the need to use .overrideValueRenderer($urlHtmlEncode) sorry i did not get your point ?? – john Gu Nov 7 '16 at 14:34
  • and if i want to use $urlHtmlEncode(linkURL); ,, then i could face a problem that the url is being encoded twice; one using $urlHtmlEncode(linkURL); and the other using the existing .overrideValueRenderer($urlHtmlEncode).. is this scenario valid ? – john Gu Nov 7 '16 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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