Search code examples
meteormeteor-blaze

How to escape current blaze {{#each}} interation


This is the routes templateData

this.route('editSession', {
    path: '/dashboard/events/:_id/editSession/:_sid',
    template: 'editSession',
    layoutTemplate: 'dashboard_layout',
    data: function () {
        var sId = this.params._sid;
        var eId = this.params._id;

        var templateData = {
            session: Sessions.findOne({ _id: sId }),
            event: Events.findOne({ _id: eId })
        };

        return templateData;
    }
})

I'm trying to use the events object being passed through the router, but when I use events._id in the template, nothing renders because it is within the #each tags for the session. How can I escape it so I am able to use another data object?

{{#each sessions}}
        <h3>Session</h3>
        <p>{{name}}</p>
        <p>{{description}}</p>
        <p>{{startTime}} - {{endTime}}</p>
        <a href="/dashboard/events/{{events._id}}/editSession/{{_id}}"><button class="btn btn-danger">Edit Session</button></a>
{{/each}}

Please help. So stuck. Would be really appreciated :)


Solution

  • In spacebars you can use ../ to jump up one context level. Assuming event is in the enclosing context of the #each you can do this:

    <a href="/dashboard/events/{{../event._id}}/editSession/{{_id}}">
    

    Note: I'm using the singular event, as specified in your router.