How do custom Handlebars Helpers work?

Hi,

I’m about to create custom helpers to provide some SVG image embedding functionality, and I’ll need to know how helpers actually work to make the site efficient. Do I understand properly, that each page is generated running all the helpers in the template, and then everything is cached?

It would also be important to know what kind of context data is available in a helper? In my implementation, there would be many helper calls on each template, and all the calls would need to see the parameters of other calls. Can I do that in some way?

(I think my question is not version nor configuration dependant)

If you’re trying to embed svgs, it seems like partials will do what you’re looking for.

As far as I’m aware, the caching that’s mentioned happens at the handlebars layer - I don’t think the final page is cached (especially with members since there can be member-specific information in the page)

1 Like

Cool, thank you, I checked, I think you’re right, that’s what I need.

Though I have a question regarding implementation:

As I will need to check the SVG-s for double ids for example, is it a best practice to create some script tool out of Ghost’s scope to generate the partials from the SVG-s after checking for possible mistakes like this id problem, or is there anything within Ghost’s scope for this?

This is definitely something out of Ghost’s scope. You can think of Ghost theme development just like development using most modern frontend frameworks (main difference being there’s no javascript handholding) - the core of the framework does all the work of generating the HTML, while other tools (like bundlers or linters) handle the preprocessing aspects