Button controlling #each loop

I have worked through a polling tutorial which includes the following #each loop:

{{ #each polls }} {{ >poll }} {{ /each }}

I am looking for the best way to insert a button into the loop so each poll waits for the button (submit if you will) before the next one is presented, which should replace the previous poll.

You can not interrupt rendering of a loop. Your best bet would be to store the polls in an array during your template creation and then create a mechanism that steps through the polls when you click the button. Or, depending on the number of polls (collection) you could work with subscribe/publish and limit/step.


Thank you for that information. Since I will have a database of polls,
it sounds to me like I should create a page with a single poll. When the
user responds to that, I can load in another poll and refresh the page.
To do this it appears I need to learn about iron-router. Does that sound
like a reasonable approach?

You should use Flow Router instead of Iron Router. Then you can simply create a page that loads if the URL is something like .../poll?id=1 or .../poll/1

@ jhuenges http://forums.meteor.com/users/jhuenges

First time I heard about Flow Router. Thank you. Sounds like it will
make things easier.

that sounds like a MUCH better approach than a loop. You could keep track of which poll a user has already seen and simply/randomly serve up a single poll that hasn’t been taken yet.