[Solved] Get label from Schema to template?


#1

I have Collection 2 and autoform installed. And I have the following codes:

Schema:

Schema.ShopList = new SimpleSchema
  item:
    type: String
    label: 'Item Name'
  budget:
    type: Number
    label: 'Budget'

Publish and Subscribe:

if Meteor.isServer
  Meteor.publish 'shoplist', -> ShopList.find()
if Meteor.isClient
  Meteor.subscribe 'shoplist'

Fixture data:

testItems = [
  { item: 'Foobar', budget: 100 },
  { item: 'Pancake', budget: 200 }
]

routes in Iron-Router

Router.route '/item-details/:_id',
  name: 'individualItemPage'
  data: -> ShopList.findOne @params._id

Everything works fine in template:

template(name='individualItemPage')
  table
    tr
      td [Item]
      td #{item}
    tr
      td [budget]
      td #{budget}

Question: How can I assign the label of Schema to [Item] and [Budget] the template?

I do a lot of trial and errors, and Google Search doesn’t help either. Please teach me.

Many thanks in advance!


#2

#3

Thanks!

Err… I did not read the last paragraph “To get the label for a field”, and I found that I forgot to declare this.Schema in coffeescript.

So, the problem is solved by:

Schema:

@Schema ?= {} # in all files about collections

Item Page coffeescript file:

Template.individualItemPage.helpers
  testLabel: Schema.ShopList.label 'item'

Thanks for help!