Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@thesebi thesebi commented Mar 17, 2018

Cool, just what i needed.

@heaven7

This comment has been minimized.

Copy link

@heaven7 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