Basically I have my "Home"-Template which shows two identically tables with different content. The tables on the Home-Template are showing just the latest five "orders" per table. With a click on the table header(h2 in Template "showLatestOrders"), I want to route to their own Template where a complete list is shown.
I know I could just many different Templates. But this seems very ugly.
I'm using iron:router and I wonder how I can make this "pathFor" in my Template "showLatestOrders" dynamic, so I just need one Template for all my overview tables.
Templates:
<template name="home">
<div class="container">
<h1>Home</h1>
<div>
{{> showLatestOrders heading="Closed Orders" data=getLatestClosedOrders}}
</div>
<div>
{{> showLatestOrders heading="Open Orders" data=getLatestOpenOrders}}
</div>
</div>
</template>
<template name="showLatestOrders">
<h2><a href="{{pathFor 'orderOverview'}}">{{this.heading}}</a>
</h2>
<div>
<table >
<thead>
<tr>
<th>Number</th>
<th>Price</th>
</tr>
</thead>
<tbody>
{{#each data}}
<tr>
<td>{{number}}</td>
<td>{{price}}</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
</template>
<template name="orderOverview">
<div class="container">
<h1>How to get a dynamic heading and collection here, based on where the route comes from?</h1>
{{> reactiveTable collection=getOrders }}
</div>
</template>
Helpers:
Template.home.getLatestOpenOrders = function () {
var data = Orders.find({
// get just open orders
}, {
limit: 5
});
return data;
}
Template.home.getLatestCompletedOrders = function () {
var data = Orders.find({
// get just completed orders
}, {
limit: 5
});
return data;
}
Template.orderOverview.getOrders = function() {
return Orders.find({});
};