Search code examples
meteorspacebarsmeteor-helper

Meteor spacebars property key not working


I'm trying to print a JSON API response using templates in Meteor. For testing purposes I have manually entered it into a:

Template.body.helpers({
entries: [
    {
        "item_link": "http://www.blocket.se/ostergotland/Tannefors_62513807.htm?ca=14&w=1",
        "item_link/_text": "Tannefors"
    },
    {
        "item_link": "http://www.blocket.se/ostergotland/Moblerad_1_a_i_Duvkullen_62466395.htm?ca=14&w=1",
        "item_link/_text": "Möblerad 1:a i Duvkullen"
    }
]}

The problem is the "item_link/_text" key, which doesn't work using Meteors template engine.

<body>
   {{#each entries}}
       {{> entry}}
  {{/each}}
</body>

<template name="entry"> 
    <h2>{{item_link/_text}}</h2>     
    {{item_link}}     
</template>

The "item_link" property works fine, but "item_link/_text" does not work, I guess it's because of the frontslash. I have tried things like escape it with "\\", but no luck.

Running example http://meteorpad.com/pad/e4D37M5ipdXcgmABG/Special%20character%20fail


Solution

  • As you can see in the spacebars readme, you can simply wrap it in square brackets like this:

    <h2>{{ [item_link/_text] }}</h2>
    

    Here's a working copy of your example.