Reputation: 836
I'm trying to set the first page to load in my meteor app, depending on whether the user is registered or not. (If user isn't logged-in load the x template, otherwise load the signIn template).
The issue I have is that my sign-in template have links to other templates (Recovery password and sign-up) which are not working (the page always stay in sign-in template probably by my "if currentUser" clause). Probably I'm approaching it in a wrong way.
Any idea how to set the first page to load? This is my html:
<template name="main">
{{#if currentUser}}
{{> header}}
{{> yield}}
{{else}}
{{> entrySignUp}}
{{/if}}
</template>
<template name="home">
{{#if eventJoined}}
{{> board}}
{{else}}
{{> findEvent}}
{{/if}}
</template>
These are my routes. Myapp.js:
Router.route ('/home')
Router.route('/', { template: 'home'});
Router.configure({layoutTemplate: 'main'});
Router.route('/findEvent');
Router.route('/board');
Upvotes: 0
Views: 252
Reputation: 1178
You need to specify which route renders which template like this:
Router.configure({
layoutTemplate:'mainTemplateName',
loadingTemplate: 'loadingTempName'
});
Router.route('/', function() {
this.render('home');
});
Router.route('/another-route', function() {
this.render('anotherTemplate');
});
Any of those templates will render to {{> yield}} so, if you have it inside if currentUser
, it won't be able to render those for non-users.
EDIT
Your main/layout template should contain the main elements of the layout like navigation bar, footer, sidebar etc. They only render once when the user enters the site. {{> yield}} specifies where the rest of the templates should render when the user goes to other routes, without changing/re-rendering the elements in layout/main template
EDIT-2 In your main template, you have this:
{{#if currentUser}}
{{> header}}
{{> yield}}
{{else}}
{{> entrySignUp}}
{{/if}}
which means the {{> yield}}
for iron:router is only for logged in users. You need the yield to be for all visitors so that the users can go to other routes/iron router can render other templates like recover password/signup as you wrote in your question. So, include the {{> yield}}
outside of {{#if currentUser}}
and use it wherever else its necessary. For example:
Main template:
<template name="layout">
{{> navigation}}
<div class="content-area">
{{> yield}}
</div>
</template>
<template name="navigation">
This will always be visible in every route according to the template above.
</template>
You can also do a check in your router.js to determine what to render like this:
Router.route('/', function() {
if(Meteor.user()){
this.render('someTemplate') //for logged in user in route '/'
} else {
this.render('entrySignUp');
}
});
Router.route('/findEvent');
Router.route('/board');
In this case, no matter which route you go, the templates above will always render to {{> yield}}
, not depending on if its a user or not but {{> yield}} should be available for both logged in and logged out users for iron router to actually have a place to render templates for none-users, in your case.
Upvotes: 1