javascript - HandlebarsJS registerHelper for comparing two dates -



javascript - HandlebarsJS registerHelper for comparing two dates -

i want create helper can compare 2 dates between each other, , depending if date has passed show specific html elements or not. have info receive remote json contains "date" field. example:

data: { date: "2014-10-04", event: "some past event, }, { date: "2014-12-06", event: "some future event, ...

so, if date has passed , want either hide html or archive it, , upcoming events want display of course. far tried this:

handlebars.registerhelper('has_passed', function(datestring, options) { var current_date = moment(datestring).format("yyyy-mm-dd").touppercase(); // current date if(current_date> here???) { homecoming options.fn(this); // if current date "bigger" passed date show html } });

and html looks now

{{#has_passed date}} <div> <h1>blablabla</h1> </div> {{/has_passed}}

clearly, doesnt work can help me out here??

many :-)

i think utilize query functions of momentjs

then helper so:

class="lang-js prettyprint-override">handlebars.registerhelper("has_passed", function(datestring, options) { if(moment(datestring).isafter(moment())){ homecoming options.fn(this); } else { homecoming options.inverse(this); } });

see fiddler

javascript handlebars.js

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -