[solved] Call helper from another helper's context (or smth like that ;)


Hey guys! I’m a bit fuzzy about spacebars data contexts and stuff… Can someone plz help out with this:

My tpl.jade:

  +each city
    .item(data-id='#{_id}') #{name} , #{parentRegion}

My .coffee:

  city:-> Geo.find({type:'city'})
  parentRegion: -> Geo.find({type:'region'})

My Geo collection:

    "_id" : "RU-R001-C001",
    "name" : "Moscow",
    "type" : "city"
    "_id" : "RU-R001",
    "name" : "Moscow Region",
    "type" : "region"

I want to have the following text in my .item: 'Moscow, Moscow Region’
My logic was to get the _id of the city, lookup its parent region (via 7 first chars of the _id) and produce parent’s name. But I don’t actually know how to realize that logic.


Ok, figured it out using this SO question and native spacebars syntax (couldn’t figure it out in meteor-jade syntax). Essentially I just pass _id parameter to parentRegion helper. It’s cool that it can actually get that _id from that particular context :thumbsup:
Here is my code after edits:

  +each city
    .item(data-id='#{_id}') #{name}, {{parentRegion _id}}


  city:-> Geo.find({type:'city'})
  parentRegion: (id)->
    id= new RegExp('^'+id.slice(0,7))

Hope this’ll help others)