0

I have made a function that will deal with many templates on created and destroy. Since writing each template helper(created/destroyed) will be repeatable I thought of making a templates array, and a function which calls Template.template-variable.created *and* Template.template-variable.destroyed on a forEach loop (of templates array).

At first when I ran it as Template.template-variable.created/destroyed = function() {}; I was running through an error saying template-varible not defined, as it was taking it as is.

Then I made a variable as var created = 'Template.' + template-variable + '.created';

And then used it as created = function() {}; instead of Template.template-variable.created = function() {};

And here is where I end, cause, Meteor no longer brings Template ref. error, but won't run the code inside the function, even tried console.log('created'); didn't work.

I need help.

ArchNoob
  • 3,946
  • 5
  • 32
  • 59
  • 1
    Can you explain what you are trying to accomplish in more detail? It's hard to help without knowing more about the end goal. – David Weldon Sep 03 '15 at 01:08
  • @DavidWeldon According to the few pieces of code provided, this seems to boil down to a misunderstanding of JS notation and assignment... Thus, this question is a duplicate of https://stackoverflow.com/questions/20736758/difference-between-dot-notation-and-bracket-notation-in-javascript or https://stackoverflow.com/questions/4968406/javascript-property-access-dot-notation-vs-brackets – Kyll Sep 03 '15 at 01:30
  • @Kyll I don't think that's the case at all. I just don't think he has a complete understanding of how to structure a Meteor/Blaze app and needs to be pointed in the right direction. – ffxsam Sep 03 '15 at 06:14
  • @ffxsam As can be seen from the self-answer, it is indeed a duplicate of the two questions I provided. – Kyll Sep 03 '15 at 10:20

1 Answers1

0

Thank you for pointing out that notation, I totally forgot it, and as soon as I saw the suggestion headline it worked out the problem.

Well what I was trying to do is to put an array of templates objects, and to iterate it with a single helper method (created & destroyed) to control what happens when each gets (created & destroyed).

So, Template[template-variable].created & Template[template-varible].destroyed, did the magic..!

ArchNoob
  • 3,946
  • 5
  • 32
  • 59
  • If the question signaled as a duplicate did answer your question, then you can accept it as a duplicate (which will close your question). – Kyll Sep 03 '15 at 10:21