Skip to content

Instantly share code, notes, and snippets.

@githubrsys
Last active July 20, 2022 09:59
Show Gist options
  • Select an option

  • Save githubrsys/398e7cc380299cea712d to your computer and use it in GitHub Desktop.

Select an option

Save githubrsys/398e7cc380299cea712d to your computer and use it in GitHub Desktop.
TYPO3 fluid VHS: Group elements with wrap without Modulo

Summary

Imagine you have a list of elements. E.g. some DIV's (or something else) and you want to surround or wrap blocks or chunks of 3 with an <li> element.

Expected output Code

<li>
<div>foo</div>
<div>foo</div>
<div>foo</div>
</li>
<li>
<div>foo</div>
<div>foo</div>
<div>foo</div>
</li>
<li>
<div>foo</div>
<div>foo</div>
<div>foo</div>
</li>

Solution with VHS

<f:for each="{foo -> v:iterator.chunk(count: 3)}" as="bar" iteration="cycle">
    <li>
        <f:for each="{bar}" as="user">
            <f:render section="yourTarget" arguments="{_all}" />
        </f:for>
    </li>
</f:for>

Solution with pure fluid

<f:for each="{foo}" as="bar" iteration="cycle">
        <f:if condition="{cycle.isFirst}">
            <li>
        </f:if>
        <f:if condition="{cycle.cycle} % 3">
             <f:then>
             <f:render section="yourTarget" arguments="{_all}" />
             </f:then>
             <f:else>
             <f:render section="yourTarget" arguments="{_all}" />
                 <f:if condition="{cycle.isLast}">
                     <f:then></f:then>
                     <f:else>
                         </li>
                         <li>
                     </f:else>
                 </f:if>
             </f:else>
        </f:if>
        <f:if condition="{cycle.isLast}">
            </li>
        </f:if>
</f:for>

What you need

Conclusion

Feel the force, Luke.

Thanks

@cedricziel

@thesebi
Copy link
Copy Markdown

thesebi commented Mar 17, 2018

Cool, just what i needed.

@heaven7
Copy link
Copy Markdown

heaven7 commented Apr 24, 2019

Thanks for that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment