Check post date against current date in Handlebars

I am trying to implement a feature for my new theme: kind of an archive of posts grouped and sorted by month. I figured out how to group everything by month. Other than that I want to display the first group (current month) differently. For instance, as a <summary> of <details>, and following groups as the body of the <details>.

So I guess I simply need to check if the first group’s month is the current month. Now how do I do that?

I believe {{#match}} is my thing, so I tried {{#match date format="MM" "=" date "" format="MM"}} ... {{/match}} and it throws an error.

[index.hbs] Parse error on line 31: date format="MM" "=" date "" format=" -----------------------^ Expecting 'CLOSE_RAW_BLOCK', 'CLOSE', 'CLOSE_UNESCAPED', 'CLOSE_SEXPR', 'ID', 'OPEN_BLOCK_PARAMS', got 'STRING'

I haven’t the faintest idea what this means… Am I doing something wrong? Well, I might. But is there really a way to do what I want to do?

Thanks :slight_smile:

Can you try this?

{{#match (date format="MM") "=" (date format="MM")}}

Without the parenthesis, I don’t think the code would do what you’re expecting, or, it seems, be valid handlebars :grinning:

1 Like

You, sir, saved my day!
I suck at Handlebars and I didn’t realise that such simple syntax was there.
Thank you so much. Have a wonderful day :herb:

1 Like