TYPO3 / Fluid

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

[FEATURE] Support for boolean tag attributes #880

Closed s2b closed 2 weeks ago

s2b commented 2 months ago

TagBasedViewHelpers now have proper support for boolean attributes. Before this change, it was very cumbersome to generate these with Fluid, now it's implemented similar to popular JavaScript frameworks:

<my:viewhelper async="{true}" />
Result: <tag async="async" />

<my:viewhelper async="{false}" />
Result: <tag />

<my:viewhelper async="{null}" />
Result: <tag />

This can also be used in combination with variable casting:

<my:viewhelper async="{myString as boolean}" />

For compatibility reasons empty strings still lead to the attribute being omitted from the tag. This might change in the future, however we don't want to break templates now. ViewHelpers can define an argument manually and implement the desired behavior in the render method (this is how the ImageViewHelper in TYPO3 deals with empty alt attributes).

s2b commented 1 month ago

911

s2b commented 2 weeks ago

This PR is based on #949

s2b commented 2 weeks ago

Test run with TYPO3 core: https://review.typo3.org/c/Packages/TYPO3.CMS/+/85568