Conditionals in handlebars


#1

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


#2

Try the plural helper :slight_smile:


#3

thank you, but

I guess i misunderstood what i should do with it…

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

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

Thank you


#4

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


#5

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


#6

@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:

partials/pagination.hbs:

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

partials/pagination-content.hbs:

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

#7

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?


#8

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.


#9

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


#10

@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}}
{{/has}}

#11

that works great, thank you