Accessing parent context from template's events

Hi all,

This is my first week with meteor and I am really enjoying the project so far. However, I am not sure how to accomplish the following:

I have a simple blog with posts in it. I have a collection of posts and each post has a tag array.
In my blaze template I have nested loops. The outer loop would print the posts and the inner loop would print the tags. I want to have a delete button where I can remove tags from the post.

In order for me to update the post, I need to have the post _id property. However, I was not able to access it.

I have made a meteorpad example:
Please check line 12 from the client/app.js
I tried Template.parentData() but with no look.

Any idea?

Try the following

<template name="postTemplate">
  {{#each posts}}
      <h2>{{topic}} (ID = {{_id}})</h2>
      {{#each tags}}
        <li>{{text}}<button post="{{../_id}}" text="{{text}}" class="delete">&times;</button></li>

then you can do this in the event handler{
  'click .delete': function(e,t){
    var $b = t.$(;
    var text = $b.attr('text');
    var post = $b.attr('post');
    alert("deleteing Tag:" + text + " from post ID: " + post);
1 Like

Ahh, someone beat me to it. But here’s my solution:

Thank you @jamgold and @ffxsam for helping. All of your solutions worked with me correctly, I decided to go with @ffxsam as his solution is more straight forward and does not modify the DOM :blush: .

1 Like

Meteorpad is dead. Do you remember what the solution was? Blaze sucks