Kazi
Kazi

Reputation: 1553

In meteor if I use template name instead of body then its not working

I am in a basic level and having a problem and that is , In meteor if I use template name instead of body in Javascript file then its not working..

here is my html code :

    <head>
  <title>simple</title>
</head> 

<body>
  <ul>

    {{#each player}}

      <li> {{text}}</li>


    {{/each}}

  </ul>
</body>

<template name="shahin">

  {{player}}

</template>

javascript code:

Template.shahin.helpers({
      player: [
         { text: "This is paragraph 1..." },
         { text: "This is paragraph 2..." },
         { text: "This is paragraph 3..." },
         { text: "This is paragraph 4..." },
         { text: "This is paragraph 5..." }
      ]
   });

Now if i run this code then it does not show anything. But i change to my Tamplate name with this

Template.body.helpers

then the code is working. Can somebody please explain why is this like so? let me know why this is not working :

Template.shahin.helpers

Upvotes: 2

Views: 88

Answers (1)

blueren
blueren

Reputation: 2860

It doesn't work because you are not calling the template anywhere in your body.

Try this:

     <head>
  <title>simple</title>
</head> 

<body>
  {{> shahin}} <!-- this is where the contents of template="shahin" will render. If you don't call this, "shahin" will never get displayed -->
</body>

<template name="shahin">

  <ul>

    {{#each player}}

      <li> {{text}}</li>


    {{/each}}

  </ul>

</template>

Upvotes: 2

Related Questions