conditional-statementstypo3fluidview-helpers

Fluid condition with ContainsViewHelper


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.


Solution

  • 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>