Last active
December 31, 2015 00:59
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{#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); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
lastValue = "";
Handlebars.registerHelper('ifchanged', function(value, options) {
if(lastValue != value){
lastValue = value;
return options.fn(this);
}
});