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.

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.

| improve this answer | |
  • No worries, I've done it myself :) – Steve Holland Apr 13 '16 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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