Feature #5158

Add "true" and "false" to Fluid syntax

Added by Bastian Waidelich over 3 years ago. Updated 11 months ago.

Status:Accepted Start date:2009-10-28
Priority:Should have Due date:
Assignee:Sebastian Kurfuerst % Done:

0%

Category:Core
Target version:-
Has patch:
Votes: 2 (View)

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.

Associated revisions

Revision beaa1450
Added by Bastian Waidelich over 3 years ago

[+FEATURE] Fluid (ViewHelpers): extended format.date viewhelper by an additional "date" argument. Now you can write {f:format.date(date: 'yesterday')} in your templates. This change is backwards compatible! Relates to #5150
[+FEATURE] Fluid (ViewHelpers): extended if viewhelper by arguments "then" and "else". Now you can write {f:if(condition: 1, then: 'yes', else: 'no'} in your templates. This change is backwards compatible! Relates to #5150
[~TASK] Fluid (Core): added check for reserved keywords to TemplateVariableContainer. This relates to #5158
[~TASK] Fluid (Tests): moved and renamed VariableContainerTest

History

Updated by Sebastian Kurfuerst almost 3 years ago

  • Assignee deleted (Sebastian Kurfuerst)

Updated by Sebastian Kurfuerst almost 3 years ago

  • Status changed from New to Accepted

Updated by Bastian Waidelich almost 3 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.

Updated by Sebastian Kurfuerst almost 3 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.

Updated by Bastian Waidelich almost 3 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.

Updated by Sebastian Kurfuerst almost 3 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

Updated by Karsten Dambekalns over 2 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...

Updated by Bastian Waidelich over 2 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?

Updated by Bastian Waidelich over 2 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?

Updated by Karsten Dambekalns over 2 years ago

Bastian Waidelich wrote:

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

Well, but correct.

Updated by Stefan Neufeind almost 2 years ago

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

Also available in: Atom PDF