Passing variable for object key in blaze spacebars

Is it possible to pass variable for object key in blaze spacebars?

Example:

 {{#each groups}}
      <div class="category-card">
          <div class="category-card-left-part">
               <span class="pl-2 get-group-name">{{groupName.getCustomName}}</span>
          </div>
       </div>
  {{/each}}
Template.menuWeb.helpers({
    getCustomName: () => {
        return "some_key_name";
    },
});

I dont think this is possible - you might try {{groupName.[getCustomName]}} - but I don’t think so, a cleaner way would be to have a generic helper

Template.registerHelper("getObjKey", (obj, key) => obj[key])

then you could call it {{getObjKey groupName getCustomName}}

2 Likes

Thank you, this is perfect.