2

This is my HTML in display template. How can I assign value to href in javascript?

<span class="AnchorCls">
  <a id="link" href="#">_#=readMore=#_</a>
</span>

href should be like this:

 "/sites/Pages/BlogDetail.aspx?ID='" +newID + "'"

1 Answer 1

5

In the display template make the following change:

var listItemID = ctx.CurrentItem.ListItemID;  //change as per your ID
var blogUrl = "/sites/Pages/BlogDetail.aspx?ID=";
var viewBlogUrl = blogUrl + listItemID;

HTML would be as below:

<a href="_#= viewBlogUrl =#_" target="_blank">Blog Title</a>

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.