Fluid condition with ContainsViewHelper
Asked Answered
S

1

5

i use this condition in my fluid template:

<f:if condition="{settings.image.className} == 'lightbox'">
                <f:then>
                    ....do something
                </f:then>
        
        <f:else>
          <f:if condition="{settings.image.className} !== 'lightbox'">
                <f:then>
                 ....do something else
                </f:then>
         </f:if>
         </f:else>

</f:if>

It works fine but if $settings.image.className" is something like "lightbox container" instead of just "lightbox" it does not work of course. Unfortunately i do not know how write a condition that checks if $settings.image.className contains "lightbox" or not.

The only instructions i found are here: ViewHelper Reference .However i do not know how to apply that.

Surtax answered 14/7, 2015 at 12:31 Comment(0)
R
10

add this to the top of the partial/content Element

{namespace v=FluidTYPO3\Vhs\ViewHelpers}

and change the logic like this

<v:condition.string.contains haystack="{settings.image.className}" needle="lightbox">
   <f:then>
        ....do something
   </f:then>
   <f:else>
        ....do something else
   </f:else>
</v:condition.string.contains>
Reggi answered 14/7, 2015 at 14:29 Comment(6)
Thanks that worked. There was no need add a namespace, it was already defined this way: {namespace v=FluidTYPO3\Vhs\ViewHelpers}. Also the closing tag should be </v:condition.string.contains>.Surtax
Oh i'll correct that if someone has the same issue ;)Reggi
How do i check if the haystack contains needle "lightbox" or needle "fancybox"?Surtax
source code reference of the viewhelper: github.com/FluidTYPO3/vhs/blob/master/Classes/ViewHelpers/…Reggi
The needle has to be a string since it only checks for a string position. You have to check twice, basically, you copy the content of my answer a second time into the "else" branch. Or you use the new syntax for TYPO3 8 <f:else if="{ ... inline version of v:condition.string.contains ... }"> ....do something else </f:else>Reggi
Cheers i was looking for the TYPO3 8 syntax.Surtax

© 2022 - 2024 — McMap. All rights reserved.