Access partial params inside get/foreach helper

I’m pretty sure this is a bug, cause partial param is printed correctly outside {{#get}} helper, but not inside.


Issue Summary

  • Looks like {{#get “tags”}} helper ovverides the previous context. Not able to access the partial parameters inside the {{#get}} helper
  • Printing {{selected_tag}} (a partial parameter) inside the {{#get}} helper would echo its value.

Steps to Reproduce

  1. create a partial and send a parameter selected_tag
  2. Use get helper to get all tags
  3. Iterate with for each and check if the current tag is selected_tag with the match helper
  4. Printing {{selected_tag}} inside the {{#get “tags”}} helper echos empty string, but when echoing before it, it prints well.

Setup information

Ghost Version
Latest version 5.12 using Ghost(Pro)

Node.js Version
Using Ghost(Pro)

How did you install Ghost?
Using Ghost(Pro)

Provide details of your host & operating system
Using Ghost(Pro)

Database type
Using Ghost(Pro)

Browser & OS version
Not dependent on Browser or OS.

Relevant log / error output
Here is my partial tags_cloud:

<div class="tags-cloud" style="justify-content: center">
    <a href="/classes/" aria-label="{{t 'All posts'}}" {{^if selected_tag}}class="active"{{/if}}>{{t 'All posts'}}</a>
    <a href="#">selected: {{selected_tag}} (will print param value)</a>
    {{#get "tags" limit="all" filter="visibility:public" order="name asc"}}
    <a href="#">selected: {{selected_tag}} (will print empty string)</a>
    {{#if tags}}
    {{#foreach tags}}
    <a href="{{url}}" aria-label="{{name}}" {{#match selected_tag name}}class="active"{{/match}}>{{name}}</a>
    {{/foreach}}
    {{/if}}
    {{/get}}
</div>

<style>
    .tags-cloud a.active {
        background-color: var(--ghost-accent-color);
    }
</style>

and used in 2 places like this:

{{>tags_cloud}}

and

{{>tags_cloud selected_tag=name}}

Excuse me if this is not a bug and if this is how ghost context works. I’m pretty new to ghost development and I like it a lot! :slight_smile:

My bad, this is not a bug but how handlebars higher context is accessed through …/…

Solved using {{#match ../../selected_tag name}}

This is more like a dev post. Sorry, I would have removed this or close this, but I don’t know how. :slight_smile:

Thanks for creating ghost.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.