Working on a site in SP2013, I have created a custom display template to display a series of items. The problem is when I reference the publishing hyperlink field in the html as the src value of my a href tag it doesn't render correctly.

<div id="Item_WebPage">

    if(!$isNull(ctx.CurrentItem) && !$isNull(ctx.ClientControl)){
        var id = ctx.ClientControl.get_nextUniqueId();
        var _title = $getItemValue(ctx, "Title");
        var _linkUrl = $getItemValue(ctx, "Link URL");
        var _teamMembers = $getItemValue(ctx, "Team Members");
        var _briefDescription = $getItemValue(ctx, "Brief Description");
        var _relatedLinks = $getItemValue(ctx, "Related Links");
        var _relatedDocuments = $getItemValue(ctx, "Related Documents");

                                <div class="row engagement-team">
                            <div class="col-12 noPadding">
                                <a href="_#= _linkUrl =#_"><h2>_#= _title =#_</h2></a>
                                <h3>_#= STSHtmlDecode(_teamMembers.value) =#_</h3>
                                <p>_#= STSHtmlDecode(_briefDescription.value) =#_ </p>

                            <div class="col-12 col-sm-6 noPadding">
                            <h3>related links</h3>
                                _#= STSHtmlDecode(_relatedLinks.value) =#_
                            <div class="col-12 col-sm-6 noPadding">
                            <h3>related documents</h3>
                                _#= STSHtmlDecode(_relatedDocuments.value) =#_

It ends up rendering as follows (The value in the hyperlink field is https://www.google.com)

<a href="&lt;a href=" https&#58;="" google.com"="">google.com</a>

I assumed this is because it is grabbing more than the hyperlink value from the column. Is there a way I can parse this value so that it returns only the hyperlink value added as the src in my a href? Any advice would be appreciated.

  • which is the problematic one ? _linkUrl or _relatedLinks ? – Gautam Sheth Aug 31 '18 at 5:05

Your Answer

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

Browse other questions tagged or ask your own question.