Skip to content

Instantly share code, notes, and snippets.

@jaredtmartin
Last active December 31, 2015 00:59
Show Gist options
  • Save jaredtmartin/7910695 to your computer and use it in GitHub Desktop.
Save jaredtmartin/7910695 to your computer and use it in GitHub Desktop.
How can I make a block helper for meteor. I need something similar to django's ifchanged template tag.
{{#each meetings}}
{{#ifchanged date}}
</ul>
<div class="date">{{date}}</div>
<ul class="list-group">
{{/ifchanged}}
<li>{{title}}</li>
{{/each}}
Given this:[{title:"Foo",date:"Today"}, {title:"Bar",date:"Today"}, {title:"Foo",date:"Tomorrow"}, {title:"Bar",date:"Tomorrow"}]
Would produce:
<div class="date">Today</div>
<ul class="list-group">
<li>Foo</li>
<li>Bar</li>
</ul>
<div class="date">Tomorrow</div>
<ul class="list-group">
<li>Foo</li>
<li>Bar</li>
</ul>
This helper seems to work as long as I reset lastValue when I'm done:
lastValue = "";
Handlebars.registerHelper('ifchanged', function(value, options) {
if(lastValue != value){
lastValue = value;
return options.fn(this);
}
});
@jaredtmartin
Copy link
Author

lastValue = "";
Handlebars.registerHelper('ifchanged', function(value, options) {
if(lastValue != value){
lastValue = value;
return options.fn(this);
}
});

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