Reputation: 93804
Each row of my Accounts (a collection) is about {_id: xxx, last_name:'kuo', first_name'willy'}
I have following in my client.js
Template.accountPage.accounts = function() {
return Accounts.find({});
}
My question is in my client.html:
{{#each accounts}}
{{last_name}}
{{first_name}}
{{full_name}} # <----- how can I implement the full_name helper
# which should return account.first_name + account.last_name
{{/each}}
Above example should be simple, following is the new one:
I have following in my client.js
Template.accountPage.accounts = function() {
return Accounts.find({});
}
My question is in my client.html:
{{#each accounts}}
{{last_name}}
{{first_name}}
{{created_at}} # <----- how can I implement the created_at
# which is computed by accounts._id.getTimestamp()
{{/each}}
Upvotes: 0
Views: 804
Reputation: 201
waitingkuops method works, but only on that specific case. If you want to assign arbitrary helpers to looped items, you do something like this:
{{#each accounts}}
{{> accountItem}}
{{/each}}
<template name="accountItem">
// custom helper
{{customValue}}
// standard values
{{last_name}}
{{first_name}}
{{last_name}}
</template>
Template.accountItem.helpers({
customValue: this.first_name + this.last_name + 'hey!'
});
Upvotes: 1
Reputation: 93804
Defined the following helper can achieve the goal:
Template.accountPage.helpers({
created_at: function() {
return this._id.getTimestamp();
}
})
Upvotes: 1
Reputation: 1390
Try
{{#each accounts}}
{{last_name}}
{{first_name}}
{{first_name}} {{last_name}}
{{/each}}
Upvotes: 0