Conditionals in handlebars

Hi, first off great job!

I am trying to se a condition for displaying pagination in the footer if there is just one page

So i have something like this in footer
{{t “Page {page} of {pages}” page=page pages=pages}}
and it desplays: “Page 1 of 1”
and i would like to hide it if there is only one page

How could i achieve that using handlebars?
ps: i have tried looking at #has but with no luck or maybe i am missing something…

Thank you

Try the plural helper :)

thank you, but

I guess i misunderstood what i should do with it…

{{#plural plural='% posts'}}
		<span class="pagination-info">{{t "Page {page} of {pages}" page=page pages=pages}}</span>

i tried a bunch of ways but to no avail, could you please show me the right way?

Thank you

Oh sorry I misunderstood what you were trying to do. There’s no way to achieve that with pure handlebars, you’d need to do some combination of the #get helper and clientside JS

I feel that handlebars comes at a high cost…

I am curious of what other users that have more experience customizing ghost theme via handlebars feel about it.
Especially since we can not register new helpers / mess with the core
Is it just me or handlebars really limits what you can and can not do with your theme?
For such a trivial thing to do it seems rather hard to achieve any level of customization

1 Like

@fruit are you doing this inside the pagination.hbs file? If so you have access to the prev and next attributes so you could use a slightly ugly workaround :see_no_evil:


{{#if prev}}
  {{> "pagination-content"}}
{{else if next}}
  {{> "pagination-content"}}


{{t "Page {page} of {pages}" page=page pages=pages}}

yes, that worked, thank you

However this brings me to a question i have.

How easy is it to bring new functionalities into ghost?

I am not talking about customizing the theme but more complex subjects like memberships, say i want to build a follow system where users can follow each other and get notified on new content release. How easy or hard would you guys think it would be using ghost.

As you can tell i am still deciding on using Ghost or something else.
I loved the simplicity and the whole feel to it but i wonder if it is suited for developing a bigger project like handling new functionalities, users, follow system and so much more.

Is ghost the right tool for me or should i look to something else?

Ghost doesn’t yet have an plugin system (although it’s planned) and has so far been very much focused on being a publishing platform rather than a CMS/framework to build custom apps from.

The specific functionality that you’re talking about - memberships, newsletters, comments, etc - is a core priority that we’ll be starting with in earnest very shortly.

that would sound amazing but from what i read there are no ETAs or roadmaps for that. So there is no way of knowing when and if that will become a reality.
Anyway your answers were really helpful

I look forward on ghost releasing custom apps

@fruit sorry, I missed a simpler approach here with the {{#has}} helper:

{{#has any="prev, next"}}
    {{t "Page {page} of {pages}" page=page pages=pages}}

that works great, thank you

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.