2

I tried to code an output in twig that should look the following ( 2 columns in one row), i figured that i will need the batch function

     <div class="row">
      <div class="col-sm-6">Content</div>
      <div class="col-sm-6">Content</div>
     </div>    
 <div class="row">
      <div class="col-sm-6">Content</div>
      <div class="col-sm-6">Content</div>
     </div>

My attempt is :

 {% for block in entry.content1|batch(2) %}
  <div class="row">
    {% for block in row %}
    <div class="col-sm-6">Content</div>
    {% endfor %}
  </div>
 {% endfor %}

but it doesn't work like that, i looked it up in the twig documentation, the error from craft i get is "Variable "row" does not exist", so i tried changing it to {% for entry in block %} but that doesn't work either.

1 Answer 1

5

I think you're getting your variable names mixed up. Something like this should work:

{% for row in entry.content1|batch(2) %}
<div class="row">
   {% for block in row %}
   <div class="col-sm-6">Content</div>
   {% endfor %}
</div>
{% endfor %}

I've changed the name of the first block to row.

1
  • No worries, I've done it myself :) Commented Apr 13, 2016 at 13:14

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.