[TYPO3-mvc] FLUID: if condition with string

Peter Bücker news.naag at gmx.net
Thu Feb 24 11:56:31 CET 2011


On 02/24/2011 08:54 AM, Peter Niederlag wrote:
> Hello,
> Am 24.02.2011 02:43, schrieb Stefano Cecere:
>> i know that a
>> <f:if condition="{detail} == 'mystring'">
>> didn't work, because of parsing problems...
>> but is it gonna work in the future?
> I someone has knowledge and time to implement: yes. ;)
> It is a really badly missign feature that is driving me nuts sometimes. :-<
> Franz Koch once posted a switch/case ViewHelper that I am using when
> needing to compare strings...

Instead of a switch/case view helper, you can also use a plain compare
view helper. I use this in my code (works for all kinds of comparisons
which require type-equality):


class Tx_MyExt_ViewHelpers_CompareViewHelper extends
Tx_Fluid_Core_ViewHelper_AbstractViewHelper {

     * Returns true if $a and $b are type-equal, false otherwise.
     * @param mixed $a
     * @param mixed $b
     * @return boolean
    public function render($a, $b) {
        return $a === $b;


Use it in your view like this:

<f:if condition="{myext:compare(a: 'foo', b: 'bar')}">

Instead of constant strings, you can also use variables of course:

<f:if condition="{myext:compare(a: model.foo, b: model.bar)}">


More information about the TYPO3-project-typo3v4mvc mailing list