How can I use one template in list and single mode?

I have finished Level Up tutorials , and made their Recipe Book app.
But there teacher uses Recipe template in RecipeList

{{#each recipes}} 
    {{> Recipe}}

And then he creates new template SingleRecipe …

But I want to use the same template for both : List and Single…
Now I’ve made 2 routes , /recipes and /recipes/:id and both of them render List , if _id is “undefined”, recipes = Recipes.find({});
When id is not empty, recipes = Recipes.find({_id: id}).

Is this way correct? Just when I enter link in browser by hands , app response after ten seconds or more. But when i click on link with recipes/id , singlePage opens fast.

Also I’ve tried to use route to render single “Recipe” instead of “RecipeList”, but I don’t know how to pass single article helpers after Recipes.findOne({id: _id}). It looks like Recipe template created for using inside {{#each Recipes}} loop…

I use FlowRouter. And my app is not about recipes, but I just write it here in famous tutorial terms. For make it easier to imagine.

When you manually change the URL, the browser will reload the page, that’s probably why it’s slow, although 10 seconds sounds really slow! Does it take the same amount of time when you first load the page?

That sounds like an ok solution. Usually you’d use findOne() but it doesn’t matter from a performance standpoint or anything.

What you should probably do is instead of trying to display Recipe directly, wrap it in a SingleRecipe template. Then you can add your “single article helpers” to that template. Just like this:

<template name="SingleRecipe">
1 Like

Thanks for answer! I was worried that my English is unclear…
About long loading, may be it’s because autopublish/subscribe - I will fix it tomorrow, today I’ve remembered that I didn’t delete “autopublish” but my mongoDB are now about 40000 entities and more than 6 MB of text .
About findOne and wrapping to single template, yes it works , but when I call {{> Recipe recipe}} when recipe is helper. After this post I realized that I should study about “pass parameters to templates” and have found useful this docs: Spacebar templates. But questions still appears more than answers :slight_smile: