Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loop a collection #34

Open
dearamy opened this issue Apr 1, 2016 · 7 comments
Open

Loop a collection #34

dearamy opened this issue Apr 1, 2016 · 7 comments

Comments

@dearamy
Copy link

dearamy commented Apr 1, 2016

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

@perak
Copy link
Owner

perak commented Apr 1, 2016

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

@dearamy
Copy link
Author

dearamy commented Apr 1, 2016

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

@perak
Copy link
Owner

perak commented Apr 1, 2016

(assiming you are using blaze, not react)

And you can add code to tabs.js if you need it:

Template.TEMPLATE_NAME.events({
});

...etc...

@dearamy
Copy link
Author

dearamy commented Apr 1, 2016

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

@perak
Copy link
Owner

perak commented Apr 1, 2016

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
Copy link
Owner

perak commented Apr 1, 2016

(and your routeshould be defined to use argument)

@perak
Copy link
Owner

perak commented Apr 1, 2016

See route_params

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants