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

Cant check for "variable is not set" in Ternary Expressions #148

Closed
sascha-egerer opened this issue Sep 16, 2016 · 4 comments
Closed

Cant check for "variable is not set" in Ternary Expressions #148

sascha-egerer opened this issue Sep 16, 2016 · 4 comments

Comments

@sascha-egerer
Copy link
Contributor

It is not possible to check if a variable is not set in a ternary expression.

{ myArray.invalidVariable ? 'yes' : 'no' } Will always return yes because myArray.invalidVariable is evaluated as a string as not variable is found with this name

{('{myArray.invalidVariable}' !== '') ? 'yes' : 'no'} does also not work as the parser does not recognize this syntax as a ternary expression but simply outputs the text.

@NamelessCoder
Copy link
Member

Looks like we should change the default to NULL when variable does not exist. Regarding the more complex expression the TernaryExpressionNode and other ExpressionNodes only support strict variable references - and no nested expressions either.

@sascha-egerer
Copy link
Contributor Author

I tried that already but had no time to dig further into this. Simply changing this behavior does not work as the function getTemplateVariableOrValueItself is used and this behavior is also required in some cases.

@NamelessCoder
Copy link
Member

It would seem we should not use getTemplateVariableOrValueItself - instead we can use $renderingContext->getVariableProvider()->get('name'). The "variable or value itself" logic is intended for use in cases where you do need the hardcoded value, for example in MathExpressionNode where expression parts can be operators/operands/hardcoded numbers rather than merely variable references. The same is not true for TernaryExpressionNode which must explicitly only support template variable references.

@NamelessCoder
Copy link
Member

NamelessCoder commented Sep 19, 2016

On a side note: this expression node class could use a bit of cleanup to remove the 'true' and 'false' expression matches since they do not make sense in this context. And the expression needs a bit of love (wrong comments, too broad variable name matching) - https://github.com/TYPO3Fluid/Fluid/blob/master/src/Core/Parser/SyntaxTree/Expression/TernaryExpressionNode.php#L29

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