Skip to content

Instantly share code, notes, and snippets.

@majornorth
Created March 25, 2014 04:43
Show Gist options
  • Save majornorth/9755391 to your computer and use it in GitHub Desktop.
Save majornorth/9755391 to your computer and use it in GitHub Desktop.
Game detail conditionals
<template name="soloGameSummary">
<div class="game-summary">
{{#if organizing}}
<strong class="text-{{#if past startsAt}}muted{{else}}info{{/if}}">
{{participle startsAt past='Organized' present='Organizing'}}
</strong>
{{else}}
{{#if playing}}
<strong class="text-{{#if past startsAt}}muted{{else}}info{{/if}}">
{{participle startsAt past='Played' present='Playing'}}
</strong>
{{/if}}
{{/if}}
<strong>{{type}}</strong> {{> gameWhen}}
<div class="needed">{{#unless past startsAt}}{{numNeeded}} needed{{/unless}}</div>
<div class="place">
<div class="place-name">
{{placeName}}
</div>
<div class-"place-location">{{placeLocation}}</div>
</div>
<div class="organizer-info">
{{#unless organizing}}Added by {{creator.name}}{{/unless}}
</div>
</div>
</template>
@dwinston
Copy link

Each template has access to (1) its data context, (2) its helpers, and (3) "global" helpers.

The soloGameSummary template currently (as opposed to that in your gist) nests a whoIsPlaying template that in turn has local helpers organizing, playing, and numNeeded, which are defined in devel.js via a call to Template.whoIsPlaying.helpers.

The soloGameSummary template does not itself define those helpers, so while it has access to a data context (which is a Game that has properties like startsAt and creator.name) and to "global" helpers (defined using Handlebars.registerHelper -- I have several defined in handlebarsHelperMap in devel.js such as past and participle), it does not have access to other templates' helpers.

It seems like you may be itching to copy the helper-map argument passed to Template.whoIsPlaying.helpers and with it extend the argument currently passed to Template.soloGameSummary.helpers. Note however that the whoIsPlaying template is currently used by both the listedGameSummary and soloGameSummary templates as an expression of commonality between those templates.

@majornorth
Copy link
Author

@dwinston lol...I'm gonna have to take a few minutes of quiet time to digest that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment