Reputation: 4597
Im getting started Meteor , I use iron router to manipulate route.. so I want to pass a variable to template:
Router.route('/foo', function(){
this.render('foo', {name: 'Stack'});
});
how i can show the variable name
in the template foo:
<template name="foo">
<h2>Hi bro, how i can show the variable name here ?? </h2>
</template>
my project folder as the following structure:
/client
---/views
------foo.html
---/layout
------layout.html
/public
/server
layout.html:
<template name="layout">
{{> yield}}
</template>
any solutions please :)
Upvotes: 0
Views: 312
Reputation: 640
You can define a template helper to get the router name:
Template.foo.helpers({
name: Router.current().route.getName()
});
And then display in your template as:
{{name}}
Upvotes: 0
Reputation: 630
In your routing:
Router.route('/foo', function(){
this.render('foo', {data: {name: 'Stack'}});
});
In your template
<template name="foo">
<h2>Hi bro, how i can show the variable name here ?? </h2>
<p>Like this --> {{name}}</p>
</template>
You can pull variables from the route too:
Router.route('/foo/:someName', function(){
this.render('foo', {data: {name: this.params.someName}});
});
See Iron Router docs for more info
Upvotes: 2