0
votes

I have html like:

<template name="chargers">
  {{#each list}}
    {{> charger}}
  {{/each}}
</template>

<template name="charger">
  <p>
    {{full_name}}
  </p>
</template>

There is a Meteor Collection called Chargers and the chargers template iterates over it just fine. There is, however, no full_name attribute on that collection. That is to be computed by concatenating the name property and the address.country property.

It would seem to me that some coffee script like:

Template.charger.full_name = ->
  console.log "full name of #{self} is #{name}"

  # return name

  if address.country.length() > 0
    return "#{name}, #{address.country}"
  else
    return name

would work, but self as echoed in the first line of the function is Window. I thought the context would the the Charger object being rendered. Oddly, If I uncomment the #return name, the whole thing works (but no country). I've verified that the data is present in the collection from the console window.

Using transform on the collection seems like a big hammer just to add a pseudo-property.

I tried defining this as a helper, but the same thing happened. What's the correct approach.

1

1 Answers

0
votes

Sorry... The correct solution involved goofing around with the Coffeescript a bit:

if @address.country.length > 0
  return "#{@name}, #{@address.country}"
else
  return @name

So, the member of the collection passed to the template helper is this.memberName, and thus, should be an @ variable in Coffeescript. TIL.