Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7796353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:21:01+00:00 2026-06-01T23:21:01+00:00

In the basic leaderboard example on meteor.com there is a method called selected_name. Template.leaderboard.selected_name

  • 0

In the basic leaderboard example on meteor.com there is a method called selected_name.

  Template.leaderboard.selected_name = function () {
    var player = Players.findOne(Session.get("selected_player"));
    return player && player.name;
  };

  {{#if selected_name}}
  <div class="details">
    <div class="name">{{selected_name}}</div>
    <input type="button" class="inc" value="Give 5 points" />
  </div>
  {{/if}}

Instead I would like to return the entire player object and then have that object be treated as a context by handlebar. I wish I could say this:

  Template.leaderboard.selected_person = function () {
    var player = Players.findOne(Session.get("selected_player"));
    return player || false;
  };

  {{#if selected_person}}
  <div class="details">
    <div class="name">{{name}}</div>
    <input type="button" class="inc" value="Give 5 points" />
  </div>
  {{/if}}

The #if block above does not actually work in meteor. The #if statement is just evaluating the selected_person method and the nested {{name}} does absolutely nothing. I would like to know if it is possible to write a method so that the returned object can be used as the context of an #if block.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:21:01+00:00Added an answer on June 1, 2026 at 11:21 pm

    Solved! If I just use #with instead of #if then everything works great. As it says in the handlebar docs You can shift the context for a section of a template by using the built-in with block helper.

      {{#if selected_person}}
      {{#with selected_person}}
      <div class="details">
        <div class="name">{{name}}</div>
        <input type="button" class="inc" value="Give 5 points" />
      </div>
      {{/with}}
      {{/if}}
    

    The nested if/with is quite cumbersome and clearly not worth it for only rendering the name, but I could think of times where special rendering for more attributes of a single object would be useful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basic summary: Working on a game that generates a 15x15 grid for the player
Basic question; I have this code: var partipiansRow = '<div class=form-row ><input type=text id=name
BASIC QUESTION: Is there a way to set the mime-type (content-type) of elements inside
Basic function of my program: create number of counters (0), create number of instructions
Basic question for PHP experts out there. I'm writing a page where the variable
Basic question to which I'm sure there is a simple answer. I'm trying to
Basic hiberate question here, I want to use the sum() aggregate function for a
Basic question: How do I load an Excel template for use with POI and
Basic PHP function: //SOAP CALL function sayHello(){ $client = new SoapClient('http://Server:8080/MyClassService/MyClass?WSDL'); $response = $client->glassfishHello();
Basic Question: when does a program call a class' destructor method in C++? I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.