Template as value of a variable - How to?

I would like to display a template in dependence to conditions.



  <h1>Welcome to Meteor!</h1>
  {{> select}}
  if (condition = true){
    document.write('{{> hello}}');
  } else{
    document.write('{{> info}}');

<template name="hello">
  <button>Click Me</button>
  <p>You've pressed the button {{counter}} times.</p>

<template name="info">
    <li><a href="https://www.meteor.com/try" target="_blank">Do the Tutorial</a></li>

But it only returns the raw text ‘{{> hello}}’. Not the template. How to transfoerm the value of a template as a variable?

You don’t have to do such ugly things when you’re using Blaze :slight_smile:

Try this:

  <button>Click Me</button>
  <p>You've pressed the button {{counter}} times.</p>
  {{#if counter}} <!--Non-zero values count as "truthy"-->

(I tried to adapt it so that it would work with your standard example app)

1 Like

Yes, it works. Thanks so far for your quickly and usefully awnser.

Does exist an onload event? I want to depends it to a select dropdown. Maybe I´m ready for today and just didn´t see how easily it is… I can´t get it…

This is sort of the equivalent for onLoad in Blaze:

  //Do stuff

If you want to initialize jQuery elements and such, that’s usually where to do it. However, you usually want to avoid working in an “imperative” style if you can. Meteor is all about doing things in a more “declarative” way. I suggest going through a good tutorial before trying to get things working on your own, so you don’t do things the hard way.

1 Like