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

BC since 0.9.x - Object methods lose context when called #440

Closed
webberig opened this issue Dec 29, 2016 · 5 comments
Closed

BC since 0.9.x - Object methods lose context when called #440

webberig opened this issue Dec 29, 2016 · 5 comments

Comments

@webberig
Copy link
Contributor

I pass an object to the render function that has a getter method for this template:

The {{ model.getBakedGood() }} is a lie.

The given model has a method getBakedGood that returns this.baked_good from the model object.

This worked fine with twig.js 0.8.9, I've put a working demo in fiddle:
https://jsfiddle.net/mathieumaes/f9px5c63/

I can't seem to get Twig.js 0.9.x and up to work in fiddle, but if you try the given use case in a project, The getter method will return undefined because the context in which the method is called is actually the "root" context of the twig template (aka. { model: Object }, and not the given model object.

webberig pushed a commit to zimmo-be/twig-loader that referenced this issue Dec 29, 2016
@dave-irvine
Copy link
Contributor

I probably broke it right around here: af38035

@dave-irvine
Copy link
Contributor

I like your loader, I'll reference it in our readme :)

@webberig
Copy link
Contributor Author

webberig commented Jan 3, 2017

Thanks for looking into this! I've been looking into it myself but I haven't been able to put my finger on it...

Feel free to reference to the twig-loader, it is also mentioned in the webpack docs (http://webpack.github.io/docs/list-of-loaders.html#templating)

@ghost
Copy link

ghost commented Feb 25, 2017

I made a PR for this issue: #455

dave-irvine pushed a commit that referenced this issue Feb 28, 2017
@dave-irvine
Copy link
Contributor

Released in v1.10.3

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

2 participants