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.

1 Answer 1

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>
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>.
    – chicky
    Jul 14, 2015 at 17:43
  • Oh i'll correct that if someone has the same issue ;)
    – Hans Koch
    Jul 15, 2015 at 7:18
  • How do i check if the haystack contains needle "lightbox" or needle "fancybox"?
    – chicky
    Aug 10, 2017 at 13:24
  • source code reference of the viewhelper: github.com/FluidTYPO3/vhs/blob/master/Classes/ViewHelpers/…
    – Hans Koch
    Aug 10, 2017 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 <f:else if="{ ... inline version of v:condition.string.contains ... }"> ....do something else </f:else>
    – Hans Koch
    Aug 10, 2017 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.