Cannot Reference Settings within Each
回答済みHi,
I was looking to manage some icons for our Categories on our Homepage via the settings, so I have this (stripped down version):
{{#each categories}}
{{#is id settings.homepage_category_1_id}}
<img src="{{settings.homepage_category_1_icon}}"/>
{{/is}}
{{/each}}
But this produces errors on both settings uses (not possible to access `settings` in `settings.homepage_category_1_id`)
The handlebars documentation on Each https://handlebarsjs.com/guide/builtin-helpers.html suggests using
@../
To go up the scope, but it appears that in Guide this does not work - it throws an error on the `.`. after settings. Is there a way to access the settings object inside a scoped loop?
All HBS documentation also references 'this' in the each loop, so I think Zendesk Guide is implementing this a bit differently (scoping the loop to only be able to access 'this' maybe?)
Thanks,
Cheryl
-
Hi Cheryl,
To escape the context, use../
. This would change your example to:
{{#each categories}}
{{#is id ../settings.homepage_category_1_id}}
<img src="{{../settings.homepage_category_1_icon}}"/>
{{/is}}
{{/each}} -
Hi Christopher,
Brilliant, thanks, that's just what I needed!
It may be useful to link to there from https://developer.zendesk.com/documentation/help_center/help-center-templates/helpers/#built-in-helpers
サインインしてコメントを残してください。
2 コメント