The helper is supposed to look for hashtags and make them a route/link. Instead, it makes the text not show up. How do I fix this?
Here is the code:
handlebar.js
Handlebars.registerHelper('hashtag', function(posttext) {
posttext.html();
posttext = posttext.replace(/#(\w+)/g, "<a href='https://www.google.com/?q=$1' target='_blank'>$&</a>");
posttext.html(posttext);
});
postidem.js
<h3 class="text">{{hashtag title}}</h3>
<p class="text">{{hashtag posttext}}</p>
Try this:
Handlebars.registerHelper('hashtag', function(posttext) {
// DEBUG START : just to know that `posttext` is really what you want; remove later;
console.log("hashtag",posttext);
// DEBUG END
return posttext.replace(/#(\w+)/g, "<a href='https://www.google.com/?q=$1' target='_blank'>$&</a>");
});
Note:
Template.registerHelper
works for Meteor 0.9.1 and newerHandlebars.registerHelper
works for every version.Meteor.startup
as Blaze won't be able to find those helpers.Remember to put helper in tripple curly braces as it returns html;
<h3 class="text">{{{hashtag title}}}</h3>
<p class="text">{{{hashtag posttext}}}</p>