skip to Main Content

Currently I can get custom fields all or none. Like this

{{#each product.custom_fields}}
{{ id }} : {{ name }} : {{ value }}
{{/each}}

but what if i want to call just one of them by id or name like the below. Is there a way to do that with stencil or otherwise?

{{product.custom_fields.id:4.name}}

2

Answers


  1. You can use the existing {{if}} helper to accomplish this

    {{#if display_name '===' 'material'}}
        {{#each product.custom_fields}}
            {{id}} : {{name}} : {{value}}   
        {{/each}
    {{/if}}
    
    Login or Signup to reply.
  2. You can select a list item by id. {{product.custom_fields.id.4.name}}, however, if you want to select by name you’ll need to implement a conditional as @alyss suggested.

    See: How do I access an access array item by index in handlebars?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search