kitchen-examples icon indicating copy to clipboard operation
kitchen-examples copied to clipboard

Loop a collection

Open dearamy opened this issue 9 years ago • 7 comments

Is there any way that I can loop a collection to build some UI text like tabs?

dearamy avatar Apr 01 '16 05:04 dearamy

@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"
  }
]

perak avatar Apr 01 '16 05:04 perak

Exactly what I want! thank you~~~~~~~~~

dearamy avatar Apr 01 '16 05:04 dearamy

(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 avatar Apr 01 '16 05:04 perak

@perak and can I still use the "items" to build the route?

dearamy avatar Apr 01 '16 06:04 dearamy

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}}

perak avatar Apr 01 '16 07:04 perak

(and your routeshould be defined to use argument)

perak avatar Apr 01 '16 07:04 perak

See route_params

perak avatar Apr 01 '16 07:04 perak