Custom theme hbs helper

#1

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.

#2

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:


And a example here:

This tutorial is also useful:

#3

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

#4

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 - https://stackoverflow.com/questions/11169595/check-for-a-value-equals-to-in-ember-handlebar-if-block-helper/39249054#39249054.

Comparison helper
#5

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

Comparison helper
#6

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

Would still love to add custom helpers though!!

#7

Thanks very much for the quick response!!