[TYPO3-mvc] <f:elseif condition="">

Franz Koch typo3.RemoveForMessage at elements-net.de
Tue Aug 10 11:23:26 CEST 2010


Hey,

> I have introduced in my own viewhelpers directory (assume x is the
> namespace) a slight modified version of the if viewHelper in order to
> allow <x:elseif condition=""> </x:elseif>.
>
> In line notation
> {x:if(condition:0,then:'then',elseif:{condition:1,then:'elseif
> '},else:'else')}
>
> What do you think about it ?

to implement such I logic, I created a switch/case viewHelper pair, 
which allows some more flexibility too.

// traditional usage
<x:switch value="{foo.bar}">
	<x:case value="{matchValue"}>gimme</x:case>
	<x:case value="{whatever}">someting</x:case>
	<x:case default="true">fallback</x:case>
</x:switch>

// mixed usecase with condition support in cases
<x:switch return="firstMatch/allMatches">
	<x:case condition="{matchValue} = 1">gimme</x:case>
	<x:case condition="{f:count(subject:whatever)}">someting</x:case>
	<x:case default="true">fallback</x:case>
</x:switch>

switch/case might not be the best naming for the last usecase, but 
didn't find a better one back then.
-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list