[SOLVED] Template argument value differs between helper and event when I have more then one instance of the template


In my effort to make the code example easy to read i stripped away the part that caused the problem. I’m using a label for the input field and therefore the input field has an id and thats of course not ok when repeating the template.

I now use the layoutArea-helper as an id value and every thing works just fine.

Thanks to @robfallows for helping me with this.

--------------------- Original question below-------------------------

I want to include a Blaze template with an argument and then use the argument value in an event. The problem is that when I include the template a second time with a different argument i get the argument value from the first instance of the template in events.


<template name="UploadFormLayoutImage">
    <form class="uploadPanel">
        <input type="file" name="fileupload" id="input-field">
        <label for="input-field">Upload file</label>


{> UploadFormLayoutImage layoutArea="area1"}}
{> UploadFormLayoutImage layoutArea="area2"}}


   this.currentArea = new ReactiveVar;

    layoutArea: function() {
        return Template.instance().currentArea.get(); //Returns the correct argument value for each instance of the template.

    'change input[type="file"]': function(e, instance) {
        console.log(instance.data.layoutArea); //Allways returns 'area1'

What am I missing here?


I just copied/pasted your code and it works as expected (logs “area1” or “area2” depending on which button is clicked).

What version of Meteor are you running?


I’m running version


Me too. Can you post a repo onto github?


The fact that it’s working for you gives me hope. I will do some additional testing at my end and after that post a repo. Thanks for your help som far.