justinw
justinw

Reputation: 3966

Conditional Elements within template?

I am very new to meteor, so I am unfamiliar with certain aspects of it.

I was wondering it was possible to display certain elements within a sub-template depending on what page/'parent' level template is being displayed.

('parent' template)

<template name="aboutPage">
     {{> contactForm }}
</template>

contactForm

{{#if is aboutPage}}
    <a href="#" class="button">HOME</a>
{{/if}}

Something along the line of above. Inside of contactForm show the .button element only if the page is aboutPage. I apologize for the incorrect terminology.

Upvotes: 0

Views: 39

Answers (1)

Ethaan
Ethaan

Reputation: 11376

I recommend you to use iron:router Package.

And you define routes like this.

 Router.route('/about', function () {
      this.render('aboutPage');
    });

Now every time a user go to /aboutPage, all the html inside <template name="aboutPage"> will show.

Take a look into the iron:router Guide on GitHub

Also look this examples from iron:router.

Update(based on user comment) Create the helper

Template.example.helpers({
  showForm:function(){
     if(validation){
      return true;
    }else{
     return false;
   }
 }
})

And we use the helper like this.

<template name="example">
    {{#if showForm}}
     <!-- Form here -->
     {{else}}
     <!-- don't show form -->
    {{/if}}
  </template>

Upvotes: 1

Related Questions