Use partial parameters in #get helper

It’s possible to use post, page or tag data in #get queries (eg filter="tag:{{primary_tag.slug}}"). The helper expands the content before executing the query. But it doesn’t seem to do the same with partial parameters.

Eg in the “parent” template, I have
{{> child-posts order="id asc"}}

And then in the child-posts partial I have
{{#get "posts" order="{{order}}"}} {{posts.length}} {{/get}}

This doesn’t seem to work – I only get posts if I hard-code order="id asc". Using the parameter, the posts.length doesn’t print, which suggests the entire ‘get’ failed for being malformed.

This would be really helpful for DRY in my templates. Is there a syntax that can do this?

Have you tried directly passing the property? i.e. {{#get "posts" order=order}}

If that doesn’t work, can you confirm that the argument to the partial is defined in the same block context as the {{#get}} helper?

ref: Expressions | Handlebars

1 Like

Oh awesome, thank you so much!

Trying to understand the logic/pattern of when to use / not use moustaches: when inside a helper (as in, inside the get moustachaes), should they only be used if concatenating in a string?

I find the handlebars’ native documentation extremely hard going tbh, even by API-doc standards. They’re fine as a syntax refresh, but they don’t give context in their examples to help the newbie figure out what’s going on (as for example: when things do and do not need to be in moustaches), so they’re really hard to learn from. The course from the ghost docs is unfortunately a dead link, now.

From my recollection, Ghost actually does the handlebars interpolation, it’s not something that’s natively done. So it’s something that’s helper/parameter-specific.

I agree that the handlebars docs could be improved, it took me a few tries to find that specific section :sweat_smile:

e: cc @RyanF the Treehouse link in Ghost Handlebars Themes - Building a custom Ghost theme - Docs is broken!