Think my query was clear from the title itself. How can I link url strings with href attributes while rendering in ejs templates? Do any helpers exist for this task? I thought of converting urls to strings right along with their href attributes and then send them to templates but I guess they will then be escaped while rendering.
Even though I am using ejs for views..I wanna change the template engine if any other has this linking facility.
Update:
suppose this is the render function
return res.render("polo", {
title: "Posters",
has_next:false,
posters:posters,
offset:0
});
and here is the view
<% for (var i=0;i<posters.length;i++) { %>
<div id="<%=posters[i]._id %>" class="newstitle">
<p>
<%=posters[i].body %>
</p>
</div>
<% }; %>
Now if posters[1].body="Hello this is a good site. www.google.com" .Similarly every other element in poster array is some text which contains some urls. when posters[i].body is rendered i want the urls like "google.com" in above example to be linked. I cant use <%= url %> because I dont know where exactly the url is inside poster.body.
If you want to output to an href attribute without escaping, then, you can use <a href="<%- yourvar %>">the link.</a>
and it won't escape.
(Note, the use of the hyphen instead of the equal sign.)
Edit
OP asked how to only display the link when the url is defined.
<% if (typeof yourvar != 'undefined' && yourvar !== null) { %>
<a href="<%- yourvar %>">the link</a>
<% } %>