Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to property of other object in parent level #591

Closed
uoziod opened this issue Aug 6, 2013 · 5 comments
Closed

Access to property of other object in parent level #591

uoziod opened this issue Aug 6, 2013 · 5 comments

Comments

@uoziod
Copy link

uoziod commented Aug 6, 2013

I have 2 objects coming to template:

foo: {
  some: {
    use: "item1"
  },
  thing: {
    use: "item3"
  }
},
bar: {
  item1: {...},
  item2: {...},
  item3: {...}
}

Using {{#each}} helper I switching every foo's property. Inside of each we have use property contains text value of property in bar object that I want to use.

How can I get access to them?

{{doSomething ../bar.[this.use]}}

Doesn't work.

@doowb
Copy link

doowb commented Aug 6, 2013

@uoziod In this case, I would pass the bar object and the this.use to the doSomething helper, and update the doSomething helper to get the correct item:

handlebars.registerHelper('doSomething', function(items, itemname) {
  var item = items[itemname];
  ...
  return 'something done';
});
{{doSomething ../bar this.user}}

Hope this helps.

@uoziod
Copy link
Author

uoziod commented Aug 6, 2013

In this case I have another question: how to access to results of helper1 inside of helper2?)

@doowb
Copy link

doowb commented Aug 6, 2013

You can call helper1 from within helper2...

Handlebars.registerHelper('helper2', function(input) {
    // pass input to helper1 to do something
    var output = Handlebars.helpers.helper1.call(this, input);
    // do something else
    var finaloutput = output;
    return finaloutput;
});

There isn't a way to chain helpers within the markup/template syntax though.

@uoziod
Copy link
Author

uoziod commented Aug 7, 2013

@doowb, great! Thank you!

@kpdecker
Copy link
Collaborator

Closing as I think this is answered (thanks @doowb) and #569 tracks the in-language support for something like this, whatever that might look like.

Please let me know if there are still issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants