Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor display array inside a collection

I want create a posts model, with tags, and be able to display all tags for each post. You know a best way to do it ??

I tried this

<template name='postsLists'>
  {{#each post}}
    {{> postDetails }}
  {{/each}}
</template>


<template name='postDetails'>
  title: {{title}}
  {{#each tag}}
    {{tag}}
  {{/each}}
</template>
like image 976
Nonyck Avatar asked Jan 08 '13 16:01

Nonyck


2 Answers

You need to use this keyword to get value from an array:

<template name='postDetails'>
  title: {{title}}
  {{#each tag}}
    {{this}}
  {{/each}}
</template>
like image 133
Ondrej Kvasnovsky Avatar answered Oct 06 '22 23:10

Ondrej Kvasnovsky


This code won't work:

{{#each tag}}
  {{tag}}
{{/each}}

because "tag" here refers to both the list and an element in that list. Try:

{{#each tags}}
  {{tag}}
{{/each}}
like image 24
Rahul Avatar answered Oct 06 '22 22:10

Rahul