Skip to content

Instantly share code, notes, and snippets.

@mplatts
Last active September 19, 2015 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mplatts/e1855a8f3630334aa557 to your computer and use it in GitHub Desktop.
Save mplatts/e1855a8f3630334aa557 to your computer and use it in GitHub Desktop.
templates - spacebar helpers
<template name="headingWrapper">
<h1>{{> UI.contentBlock}}</h1>
<h4>{{this.subheading}}</h4>
</template>
<template name="main">
{{#headingWrapper subheading="My Subheading"}}
My Heading
{{/headingWrapper}}
</template>
UI.registerHelper('truncate', function(stringToShorten, maxCharsAmount){
if(stringToShorten.length > maxCharsAmount){
return stringToShorten.substring(0, maxCharsAmount) + '...';
}
return stringToShorten;
});
// Usage:
// {{truncate name 50}}
Template.registerHelper 'formattedDate', (timestamp, format) ->
moment(new Date(timestamp)).format(format)
// {{formattedDate createdAt "ddd, hA"}}
// => "Sun, 3PM"
// Note this requires package "momentjs:moment"
<template name="layout">
<div class="wrapper">
{{>nav}}
{{>yield}}
<div class="push"></div>
</div>
{{>footer}}
</template>
{{#each users}}
<li><a href="{{pathFor 'modulesList' username}}">{{username}}</a></li>
{{/each}}
{{#if currentUser}}
{{else}}
{{/if}}
{{#if loggingIn}}{{/if}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment