Question

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!

Was it helpful?

Solution

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.

OTHER TIPS

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top