Why Does Inserting an #if Spacebars Tag in a Meteor Template Cause an Empty Page to Be Rendered?

StackOverflow https://stackoverflow.com/questions/10133166

  •  31-05-2021
  •  | 
  •  

سؤال

I'm playing with the promising meteor framework and hit a wall. Inserting the {{#if something}}{{/if}} anywhere in my template causes rendering an empty page. Consider this template:

<head>
    <title>MUse - XUse on Meteor</title>
</head>

<body>
    {{> menu}} {{> login }}
    {{> hello}}
</body>

<template name="hello">
    <div class="hello">
      <h1>This is Xuse on Meteor a.k.a. <em>MUse</em></h1>
    </div>
</template>


<template name="login">
    <div class="login">
      <label for="username">Login:</label>
      <input type="text" id="username" value="" placeholder="Login"/>
      <label>Password:</label>
      <input type="password" id="password" value="" placeholder="Password"/>
      <input type="button" id="signin" name="signin" value="Sign in" />
    </div>
</template>

<template name="dashboard">
    <div class="dashboard">
      Hi, {{login_name}}.
    </div>
</template>

<template name="menu">
    <nav>
      <a href="/#dashboard">Dashboard</a> |
      <a href="/#logout">Log out</a> |
      {{#if login_name}}
      <a href="/#{{login_name}}">{{login_name}}</a>
      {{/if}}
    </nav>
</template>

And just in case the coffeescript code:

if Meteor.is_client
  Template.hello.greeting =  ->  "Welcome to muse."

  Template.login.events =
    'click #signin' :  ->
        console.log "You pressed the 'sign in' button" if console?
        login_name = $('#username').val()
        password = $('#password').val()
        console.log "Credentials: #{login_name} -> #{password}" if console?

  Template.menu.events =
    'click a[href*="dashboard"]' : ->
        console.log "Menu -> Dashboard invoked" if console?
    'click a[href*="logout"]' : ->
        console.log "Menu -> Log out invoked" if console?

if Meteor.is_server
  Meteor.startup ->
    time = new Date
    console.log "#{time} Hi. This is server" if console?

That's all -- nothing more. Removing the {{#if...}} sequence causes proper rendering, while leaving it in place or placing anywhere it makes sense renders empty page. Any clue?

I did try the todos example and it worked on the very same machine, so this is not an installation issue. BTW the machine is a poor old laptop Asus A6Rp with Ubuntu 12.04 on board.

هل كانت مفيدة؟

المحلول

You need to define the login_name in the coffee script also on the correct template, here is an example in javascript:

Template.menu.login_name = function () {
  return $('#username').val();
};

Not 100% on coffeescript but I'm sure you get the picture:

Template.menu.login_name = -> $('#username').val()
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top