Loop a collection
Is there any way that I can loop a collection to build some UI text like tabs?
@dearamy I am not sure do I understand your question. Maybe you want this:
create two files inside directorywhere is your .json input fie for the kitchen. Both files with the same name but different extension:
tabs.html tabs.js
inside tabs.html put:
<template name="TEMPLATE_NAME">
{{#each QUERY_VARIABLE}}
...html content for each item here...
{{/each}}
</template>
Now, in your .json input file, in some page, add component:
... inside page...
"components": [
{
"name": "my_tabs",
"type": "custom_component",
"template": "tabs",
"query_name": "name_of_your_query_here"
}
]
Exactly what I want! thank you~~~~~~~~~
(assiming you are using blaze, not react)
And you can add code to tabs.js if you need it:
Template.TEMPLATE_NAME.events({
});
...etc...
@perak and can I still use the "items" to build the route?
Did you mean to build link to route (you are creating menu?). Yes you can, inside "each" block {{pathFor "route_name" some_argument=field_name_from_query}}
(and your routeshould be defined to use argument)
See route_params