Custom theme hbs helper

Feature request

Consider adding a custom helper feature?

like this

 .
 ├── /assets
 |   └── /css
 |       ├── screen.css
 |   ├── /fonts
 |   ├── /images
 |   ├── /js
+├── /helpers
+|   ├── helper1.js
+|   └── helper2.js
 ├── default.hbs
 ├── index.hbs [required]
 └── post.hbs [required]
 └── package.json [required]

or

 .
 ├── /assets
 |   └── /css
 |       ├── screen.css
 |   ├── /fonts
 |   ├── /images
 |   ├── /js
 ├── default.hbs
+├── functions.js
 ├── index.hbs [required]
 └── post.hbs [required]
 └── package.json [required]

In this way, we can add more advanced features to the theme more easily.

If there is no problem, I can contribute the pr code.

It’s easy to add custom helpers with Ghost-App module.
Use npm install ghost-app.
Guide has been removed, but you find it here:
https://web.archive.org/web/20181006220559/https://github.com/TryGhost/Ghost/wiki/Apps-Getting-Started-for-Ghost-Devs
And a example here:

This tutorial is also useful:

I know this method, but I think it would be better to put these helpers in the theme.

I added my vote to this but wanted to add a comment as well.

I was hoping to suppress 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.

I would add something like this - if statement - Check for a value equals to in Ember Handlebar If block helper - Stack Overflow.

@cmckulka how to suppress pagination will depend on how you are rendering pagination but if you’re talking about the code inside pagination.hbs have you tried using the {{has}} helper? Eg: {{#has any="prev, next"}}...pagination...{{/has}}

There shouldn’t be any need for custom helpers for what you are trying to do. If the {{has}} helper doesn’t work please open a new topic with more details about your template structure and exactly what you are trying to achieve.

Thanks, I’ll try that. I didn’t realize that {{#has any="prev, next"}} would work.

Would still love to add custom helpers though!!

Thanks very much for the quick response!!

I would like to add my vote to this. Something as simple as an eq helper would make theme development much easier.

1 Like

Here is a guide I wrote on similar topic, if anyone needs it.