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

Twig_String_Loader hick-up with variable names using underscores #1519

Closed
zebba opened this issue Sep 30, 2014 · 2 comments
Closed

Twig_String_Loader hick-up with variable names using underscores #1519

zebba opened this issue Sep 30, 2014 · 2 comments

Comments

@zebba
Copy link

zebba commented Sep 30, 2014

I've set-up a small test-case that demonstrates a hick-up the Twig_String_Loader currently has: it doesn't process properties that user underscores in their name, using {{ foo.acme_string }} to access $acme_string will fail with

Twig_Error_Runtime: Method "acme_string"
for object "Tests\Foo" does not exist
in "{{ foo.int }}, {{ foo.acme_string }}"

Although as per doc-comment on the Loader\String the loader should only be used for testing purposes this should work anyway. Else it is not really suitable for testing.

@stof
Copy link
Member

stof commented Sep 30, 2014

Well, actually, the Twig_Loader_Array is more suitable for testing purpose. The Twig_Loader_String does not allow extending another template (well, unless you put the content of the parent template in the {% extends %} tag, which makes it useless). The actual use case for the string loader is template_from_string().

but your own issue has nothing to do with the string loader. foo.acme_string does not work for other loaders either (it has nothing to do with the template loading btw). It looks like you expect the behavior of https://github.com/fabpot/Twig/pull/1299, but this Pr is not merged

@fabpot
Copy link
Contributor

fabpot commented Oct 11, 2014

You should never use the Twig_Loader_String loader. I made it clear in d12f7af. Use String_Loader_Array instead.

@fabpot fabpot closed this as completed Oct 11, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants