Feature #5158

Add "true" and "false" to Fluid syntax

Added by Bastian Waidelich about 12 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Should have
Category:
Core
Target version:
-
Start date:
2009-10-28
Due date:
% Done:

100%

Estimated time:
Has patch:
No

Description

Currently

{f:uri.resource(path: 'somePath', absolute: true)}

throws an exception, because the true is "translated" into {true} internally.
{f:uri.resource(path: 'somePath', absolute: 'true')}

and
{f:uri.resource(path: 'somePath', absolute: 1)}

is possible, but it would be nicer to add "true" and "false" as language constructs.

#1

Updated by Sebastian Kurfuerst over 11 years ago

  • Assignee deleted (Sebastian Kurfuerst)
#2

Updated by Sebastian Kurfuerst over 11 years ago

  • Status changed from New to Accepted
#3

Updated by Bastian Waidelich over 11 years ago

  • Status changed from Accepted to Closed

Thinking about this again - I guess, it's more consistent as it is right now:
'true' => String "true"
true => Variable $true
1 => Number 1

I'm closing this issue for now. Feel free to re-open if you do not agree or want to discuss this further.

#4

Updated by Sebastian Kurfuerst over 11 years ago

  • Status changed from Closed to Needs Feedback

I still think such a feature makes sense, the "true" string should be handled the same as the "true" constant / variable, and the same as 1.

#5

Updated by Bastian Waidelich over 11 years ago

Sebastian Kurfuerst wrote:

I still think such a feature makes sense, the "true" string should be handled the same
as the "true" constant / variable, and the same as 1.

Ok, might be more intuitive that way.. But then we should make sure, that those "constant" variables are reserved and something like

$this->view->assign('true', 'foo');
$this->view->assign('FALSE', 'bar');

is not possible.

#6

Updated by Sebastian Kurfuerst over 11 years ago

Yep, they cannot be re-declared, see
$reservedVariableNames inside https://svn.typo3.org/TYPO3v4/CoreProjects/MVC/fluid/trunk/Classes/Core/ViewHelper/TemplateVariableContainer.php :-)

Greets,
Sebastian

#7

Updated by Karsten Dambekalns about 11 years ago

  • Status changed from Needs Feedback to Accepted
  • Assignee set to Sebastian Kurfuerst

Seems the feedback state is resolved, I would be happy to have true be true and 'true' be a string. Noone wants a variable named true anyway...

#8

Updated by Bastian Waidelich about 11 years ago

Karsten Dambekalns wrote:

I would be happy to have true be true and 'true' be a string.
Noone wants a variable named true anyway...

'true' is a string but is converted to TRUE when used in boolean arguments:

<f:if condition="some sting">
or
{f:if(condition: 'some string')}

will always be true for non-empty strings (even 'false').

The correct way to write it (when boolean constants are available) would be

<f:if condition="{true}">
or
{f:if(condition: true)}

right?

#9

Updated by Bastian Waidelich about 11 years ago

Bastian Waidelich wrote:

The correct way to write it (when boolean constants are available) would be
[...]

thinking about it again..

<f:if condition="false" />

would be true, which is a bit confusing, innit?

#10

Updated by Karsten Dambekalns almost 11 years ago

Bastian Waidelich wrote:

thinking about it again..
[...]
would be true, which is a bit confusing, innit?

Well, but correct.

#11

Updated by Stefan Neufeind over 10 years ago

Bastian, I agree that the string (althought it contains "false") should evaluate to true. It's a string after all ...

#12

Updated by Bastian Waidelich over 8 years ago

  • Status changed from Accepted to Closed
  • % Done changed from 0 to 100
  • Has patch set to No

This has been resolved a long time ago (I can't find the respective issue at the moment).

BTW: The behavior is:

<!-- TRUE: -->
{f:if(condition: 'someString')}
{f:if(condition: 1)}
{f:if(condition: '1')}
{f:if(condition: someCollectionWithAtLeastOneItem)}

<!-- FALSE: -->
{f:if(condition: '-1')}
{f:if(condition: '0')}
{f:if(condition: 'FaLsE')}
{f:if(condition: '')}
{f:if(condition: null)}
{f:if(condition: someEmptyCollection)}

So

<f:if condition="false" />

is (and has been) FALSE in fact - see https://git.typo3.org/FLOW3/Packages/TYPO3.Fluid.git/blob/HEAD:/Classes/TYPO3/Fluid/Core/Parser/SyntaxTree/BooleanNode.php#l324

Also available in: Atom PDF