When searching the Internet for how to compare two strings in TYPO3’s templating engine Fluid, you will still find a lot of pages telling you to do it this way:
1 2 3 |
<f:if condition="{0:myvar} == {0:'test'}"> Displayed if myvar is "test". </f:if> |
Basically you had to create two single valued arrays and compare their values. This has always been an awkward workaround. But over the time you got used to it.
But today I realized that this is not up-to-date anymore – in fact for quite some time. Already since version 6.1 of TYPO3 CMS string comparison in Fluid is more like you’d expect it to be:
1 2 3 |
<f:if condition="{foo.bar} == 'stringToCompare'"> Will result true if {foo.bar}'s represented value equals 'stringToCompare'. </f:if> |
Clean and natural, as this example taken from the comments of the current Fluid IfViewHelper shows.
Strange thing is that even official TYPO3/Fluid documentation doesn’t necessarily tell you about this change (like e.g. the TYPO3Wiki, from where the first example was taken), what might have caused me (and others probably, too) to overlook it. So I hope this post will help to spread the word about this small, but noteworthy fact.