1

I am iterating over multiple addresses, and I want them in rows with 2 columns each. The way to achieve this with Twitter Bootstrap would be something like this:

<div class="row-fluid">
    <div class="span6">First Address</div>
    <div class="span6">Second Address</div>
</div>
<div class="row-fluid">
    <div class="span6">Third Address</div>
    <div class="span6">Fourth Address</div>
</div>

I can't seem to get Thymeleaf to do this in a single th:each statement. Is it even possible?

1 Answer 1

2

You can break your array into chunks, based on the number of columns you want. So, for two columns, you could do the following:

<div th:each="addressChunks : ${T(com.google.common.collect.Lists).partition(customerAddresses, 2)}" class="row-fluid">
    <div th:each="address : ${addressChunks}" th:object="${address}" class="span6">
        <address></address>
    </div>
</div>

Your Answer

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

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