Double curly braces in SafeString from template helper

I return the following from a template helper:

return new Spacebars.SafeString("<a href=\"{{pathFor 'find_contact_persons_page' companyId=this._id}}\"> Click Here: " + this._id + "</a>");

However, the link is not created correctly in the HTML. It looks like this:


Something is totally wrong… Please help

You’re mixing Spacebars syntax in with your HTML and injecting it into the template at run time. That’s not going to work. Just put pure HTML into the Spacebars.SafeString or move this all into the template itself, where the Spacebars syntax will get interpreted properly at build time.

Ok, thanks, but how can I generate the route as pure HTML ?
So I can add it to the other HTML?
Many thanks…

I figured out how to do it and will write it here to help others. I was unable to find info about this in any of the docs:

var link = Router.routes['find_contact_persons_page'].path({companyId:this._id});
return new Spacebars.SafeString("<a href=\"" + link + "\"> Click Here</a>");
1 Like