Skip to content

[FEATURE] ViewHelpers without then/else return verdict#1031

Merged
s2b merged 1 commit intomainfrom
feature/ifBooleanReturn
Feb 14, 2025
Merged

[FEATURE] ViewHelpers without then/else return verdict#1031
s2b merged 1 commit intomainfrom
feature/ifBooleanReturn

Conversation

@s2b
Copy link
Copy Markdown
Contributor

@s2b s2b commented Feb 11, 2025

ViewHelpers that don't specify any then or else clause in any of the accepted syntax variants now directly return the result of the condition.

Previously, this syntax was not supported and a no-op resulting in an empty string. Thus, this is not considered a breaking change, but an enhancement of the existing behavior.

@s2b s2b mentioned this pull request Feb 11, 2025
ViewHelpers that don't specify any then or else clause in any of the accepted
syntax variants now directly return the result of the condition.

Previously, this syntax was not supported and a no-op resulting in an empty
string. Thus, this is not considered a breaking change, but an enhancement
of the existing behavior.
@s2b s2b force-pushed the feature/ifBooleanReturn branch from f76d5a6 to 2ec9e67 Compare February 11, 2025 18:44
@s2b s2b merged commit 96099a6 into main Feb 14, 2025
@s2b s2b deleted the feature/ifBooleanReturn branch February 14, 2025 12:03
'\'__then\' => %s,' . chr(10),
$templateCompiler->wrapChildNodesInClosure($node),
);
if (!isset($node->getArguments()['else']) && $node->getChildNodes() === []) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this breaks the cache if only "then" is defined.

Copy link
Copy Markdown
Contributor

@sascha-egerer sascha-egerer Apr 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm there is an !isset($node->getArguments()['then']) check in the line above so this could not be the reason.

Here is my use case:
foo.bar is an empty array.
{f:if(condition: '{foo.bar -> f:count()} == 0', then: foo.baz)}
Returns true on first execution and '' on the second execution when it is cached.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #1048

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

Successfully merging this pull request may close these issues.

4 participants