Reputation: 307
I m learning Meteor and I m building a very basic app for practice purposes. I just installed Collection FS and I m uploading files using the cfs:filesystem. I have a collection named todos witch has the following fields among others :
"files" : [ "/cfs/files/files/HPxaJrEbvNjcnmA6m/files?store=files", "/cfs/files/files/jfKua2BszyfqiKYYu/files?store=files" ]
The insert is done via method on Server side:
'addFiles':function(id,url){
todos.update(id, {
$push: {files:url}
});
How can I iterate through these to put them in urls in my template?
What I tried in my template is :
{{#each todos}}
{{#each files}}<a href="{{files}}" target="_blank"> file</a>{{/each}}
{{/each}}
Buts this renders just <a target="_blank"> file</a>
In case the files object hasn't got any values I dont want to show any url.
How can I do this?
Upvotes: 0
Views: 207
Reputation: 5273
I assume that you are properly subscribing to todos
collection and have helper:
Template.NAME.helpers({
todos : function(){
return todos.find();
}
})
In template NAME try this:
{{#each todos}}
{{#each this.files}}
<a href="{{this}}" target="_blank"> file</a>
{{/each}}
{{/each}}
If files
is empty, then nothing will be shown.
Upvotes: 1