8
I want to use one helper function in another helper function. In below code I want to highlight last name if it contains "Finch" word. I have writtern helper class for that. If we use in hbs file then syntax would be {{highlight name}}. But how to use it since I have to use it in another helper class.
Below is my code:
Handlebars.registerHelper('fullName', function(person) {
return person.firstName + " " + person.lastName;
});
Handlebars.registerHelper('highlight', function(person) {
var item = (person.lastName).replace('Finch', '<span style="color: red">'
+ Finch + '</span>');
return new Handlebars.SafeString(item);
});
Here is the working fiddle : http://jsfiddle.net/wC6JT/4/
Here is the fiddle where "highlight" helper is called.: http://jsfiddle.net/wC6JT/3/ . This will not produce any results since we will get console errors for person.lastName not recognized in "highlight" register helper.
I want to use "highlight" helper in fullname helper for person.lastName. How can this be acheived.