Comparison helper

It would be great if Ghost provided a comparison helper. For example {{#if gt(pages, 1)}}.

ember-truth-helpers is a good example. They also implement booleans.

I would add them as a custom helper myself … but I can’t. :frowning: I added vote to that request.

The scenario I was looking to solve is suppressing pagination when there is only one page, e.g. for featured posts. The if helper won’t work because pages is always at least 1 (if nothing featured I suppress the whole section). has doesn’t help here either.

Even using javascript is tricky because, in my scenario, I have two pagination blocks on the home page. I could probably solve it passing a parameter to the partial but it feels pretty clunky.

I can definitely see the use case for disabling pagination if there’s only one page. Passing a param to the partial is a sane workaround - we actually only recently made that possible for these sorts of cases.

Either way, achieving this nicely could be done with the introduction of a single boolean our side - it shouldn’t need a full suite of comparisons - but it is already possible with this logic:

{{#unless prev}}{{#unless next}}
.. there is neither a prev nor a next page
1 Like

And I’ve just seen that Kevin gave you a different answer here:

We rarely find use cases that aren’t solved with the helpers that are already available :) Most custom helper requests are people misunderstanding what’s possible, or wanting to do something better served with client side JS.

When that isn’t the case, we’ll always consider extending the existing helpers :slight_smile:

1 Like

I am new to Ghost and I really appreciate how responsive both you and the broader Ghost team are!! Makes me feel more confident in my choice.

@Kevin’s suggestion definitely solved this scenario (thanks!). Still learning my way around Ghost.

Coming from Jinja templates not being able to do comparisons in Handlebars is a weird limitation. That said I was using Jinja for much more complex sites / application functionality so it may be that for my publishing site they won’t be needed.

Thanks again!

1 Like