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 supports binary operations (+, -, *, /, ~, %, and, or)" incorrect print of boolean #88

Open
m-abs opened this issue Apr 30, 2013 · 2 comments

Comments

@m-abs
Copy link
Contributor

m-abs commented Apr 30, 2013

Twig.php follows the same rules for printing booleans as PHP does.

In PHP "false" is printed as empty string. "true" is printed as 1

{{ 1 and 0 }}

Print:

0

should print:


I'm not sure how to fix this.
I should change Twig.expression.operator.parse to add the PHP-like strings, but isn't that function both used for outputting text and the evaluating operator expressions?

I could also, make Twig.expression.operator.parse add the proper types to the stack and then parse the output at the end (the expression "a && b" add a 1 if true and 0 if false), but I don't understand the code well enough to see if this is a good idea or not.

@evgenius
Copy link
Collaborator

@justjohn , what was your main goal when you decided to create a port of PHP Twig?

Do you want Twig.js to render templates exactly how Twig.php does it?
As @m-abs reported, sometimes there is significant difference between Twig.php and Twig.js results.
If you think Twig.js should be an exact port of Twig.php, I can start working on it.

@justjohn
Copy link
Collaborator

My goal is to mimic twig PHP as closely as possible. In some cases that's not really possible, since JavaScript and PHP are different languages, but for cases like this, I see no reason not to make the change.

If you're interested in creating a fix, go for it, I'd be happy to merge it in.

I think the suggestion about annotating the output from @m-abs is the right way to go, since that provides an easy path to adding automatic escaping of output, which is currently the major difference between twig php and twig js.

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

No branches or pull requests

5 participants