1

I want to print the following HTML only if one or more of the colPos has content in it. If none have content elements in it, then I don't want to print this block (the whole "row") of HTML.

<div class="row">
  <div class="col-sm-4">
      <f:cObject typoscriptObjectPath="lib.dynamicContent" data="5" />
  </div>
  <div class="col-sm-4">
      <f:cObject typoscriptObjectPath="lib.dynamicContent" data="6" />
  </div>
  <div class="col-sm-4">
      <f:cObject typoscriptObjectPath="lib.dynamicContent" data="7" />
  </div>
</div>

I thought about getting the colPos and try to do a OR condition on Fluid. But I have no idea on how to do it. I know I can check one by one like this:

<f:if condition="{f:cObject(typoscriptObjectPath: 'lib.dynamicContent', data: '5')}">
   ...HTML for colPos 5 HERE...
</f:if>

But I don't want to do that. In my template I have almost 50 different colPos and they are organized by blocks (rows). Like colPos 1 to 5 is one block(row). colPos 10 to 25 in another block(row). But some pages will not use some blocks (rows) of colPos, so there's no reason on printing the HTML code for those blocks (rows) of colPos unused.

Thanks for your help!

mvetter
  • 133
  • 2
  • 16

2 Answers2

3

A fluid-only solution would be to assign the results of the <f:cObject>-ViewHelpers each to a variable, and then use the concatenation of these variables in a condition. The v:-namespace in the example is the namespace of the extension vhs:

<v:variable.set name="col-5" value="{f:cObject(typoscriptObjectPath: 'lib.dynamicContent', data: '5')}"/>
<v:variable.set name="col-6" value="{f:cObject(typoscriptObjectPath: 'lib.dynamicContent', data: '6')}"/>
<v:variable.set name="col-7" value="{f:cObject(typoscriptObjectPath: 'lib.dynamicContent', data: '7')}"/>

<f:if condition="{col-5}{col-6}{col-7}">
    <div class="row">
        <div class="col-sm-4">{col-5}</div>
        <div class="col-sm-4">{col-6}</div>
        <div class="col-sm-4">{col-7}</div>
    </div>
</f:if>

You should of course move this stuff to a partial, which gets an array of the columns to print as a parameter. Then you need to write the logic only once.

Also, you should think again, if you really need 25 columns.

Jost
  • 5,948
  • 8
  • 42
  • 72
  • Thanks Jost! I don't have enough score to give you a point. As soon as I have, I'll give you a point here. It didn't work exactly as I expected, but this helped me to solve the problem. The if condition doesn't compare more than 3 variables, so I merged the variables in one and id did what I needed :) Thanks!! – mvetter Aug 01 '14 at 21:26
  • You should still be able to accept the answer with the check mark below the votes. Also, the `condition` should work the way I have written, since the content of the three variables is just concatenated, and it is empty iff all three variables are empty. But your approach with another variable is still good, that way you could generalize the code snippet to work with an variable number of columns. – Jost Aug 02 '14 at 00:00
1

Since TYPO3 8.6, this is possible without extension "vhs":

<f:variable name="col-5">
    <f:cObject typoscriptObjectPath="lib.dynamicContent" data="5" />
</f:variable>
<f:if condition="{col-5}">
     <f:format.raw>{col-5}</f:format.raw>
</f:if>
Sven
  • 722
  • 1
  • 7
  • 25