Passing a parameter from the template

I need to pass the “username” to a function but I can’t find a way to do so…

I Have this template:

<template name="adminPage" >
<table border="1" align="center">
        {{#each allusers}}
            <tr><td id="user"><h6>{{username}}</h6></td>
                <td><button id="deleteUser" class="delete btn btn-danger btn-xs" >Delete User</button></td>


and this this client side script:{
'click .delete': function(e) {            

any ideas?

Do console.log(this) instead and you’ll find the correct variable


Holy Cow! I had been doing this for the last two months:

<div id="wrapper">
<class="btn" data-id='...'>

'#wrapper .btn': function (e) {
    var a = $('id');

and no one called me out on it! Man, you do not know how excited this makes me. >_<!

And as a bonus if you call that function with (e, tmp) than u will have access also to template data context as
At least I think :smiley:

:open_mouth: :open_mouth: :open_mouth: :open_mouth: :open_mouth: :open_mouth: :open_mouth: :open_mouth: :open_mouth: :open_mouth: :open_mouth: :open_mouth: :open_mouth: :open_mouth: :open_mouth: :open_mouth: :open_mouth: :open_mouth: :open_mouth: :open_mouth:

Yeah naaa, I’m wayyy ahead on this one:


gonna try it out

Could the contents of this in that context be accessed through Template.currentData or Template.parentData?

I was trying to do something similar to what @xtrim was trying, using Template.currentData, but it hasn’t been working out so far.

I tried this, but got results that differed from what I was expecting:

Inside a call to, tpl) { ... }) I put:

  • console.log(this)
  • console.log(tpl)

The output of this was: Object {}

And the output of the tpl argument was a Blaze.TemplateInstance object, but it’s data k/v pair was empty.

I guess my question is, (well, two):

  • Why was the template instance’s data object empty? There were definitely variables in the Spacebars template (e.g. {{name}} )
  • If the this object isn’t a templaate instance in the context of the Event Map (I thought it would be), what is it?


The template’s prop is not the same as this passed into events. There is no relationship I think.
The this passed into event functions refers to the context of any +each or +with object wrapping it. e.g

function (e, t) {
    // this refers to Object {} because there is no context outside of this event

// vs

+each postList
function (e, t) {
    // this has all the props of each postList as it iterates so if your postList is a db.collection.cursor you can write
    this._id // <-- post._id

// this does the same thing as +each as in it gives the function call the context of post
+with post