TYPO3 / Fluid

Fluid template rendering engine - Standalone version
GNU Lesser General Public License v3.0
152 stars 93 forks source link

Boolean and Null literals #911

Closed s2b closed 2 months ago

s2b commented 3 months ago

Currently, it is dependent on the context if true/false/1/0 will be converted to booleans or if the values will remain as-is. This can lead to confusing behavior, for example for a TagBasedViewHelper:

<my:viewhelper disabled="true" />

This will lead to something like this:

<div disabled="true"></div>

However, one would expect the following result:

<div disabled="disabled"></div>
<!-- or -->
<div disabled></div>

However, we can't just convert true or false to boolean in all places because there are cases where you would want the string "true" instead. So we probably need some kind of syntax to decide explicitly, which type should be used.

One possibility is to solve this similarly to frontend frameworks (such as Svelte):

<my:viewhelper disabled="{true}" />

Same goes for null, which should be treated similarly to true and false.

s2b commented 2 months ago

First step to accomplish this would be to "block" some variable names by throwing a deprecation: true, false, null and _all.

The end result could look something like this:

<my:viewhelper disabled="{false}" />
<my:viewhelper disabled="{falsyVariable}" />
<my:viewhelper disabled="{someVariable as bool}" />
<my:viewhelper disabled="{myString == 'test'}" />