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>

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 condtion 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.

chicky
  • 103
  • 1
  • 9

1 Answers1

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>
Hans Koch
  • 4,283
  • 22
  • 33
  • 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 . – chicky Jul 14 '15 at 17:43
  • Oh i'll correct that if someone has the same issue ;) – Hans Koch Jul 15 '15 at 07:18
  • How do i check if the haystack contains needle "lightbox" or needle "fancybox"? – chicky Aug 10 '17 at 13:24
  • source code reference of the viewhelper: https://github.com/FluidTYPO3/vhs/blob/master/Classes/ViewHelpers/Condition/String/ContainsViewHelper.php#L41 – Hans Koch Aug 10 '17 at 13:32
  • 1
    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 ` ....do something else ` – Hans Koch Aug 10 '17 at 13:37
  • Cheers i was looking for the TYPO3 8 syntax. – chicky Aug 10 '17 at 13:46