0

I am working with symfony 2. I am fetching records from table and sending it to the view: Below is the php code that normally prints each value of the array:

<tbody>
      <?php foreach($categories as $row){?>
         <tr>
           <?php foreach($row as $name => $value){ ?>
               <td><?php echo $value;?></td>
           <?php }?>                                      
         </tr>
      <?php }?>
</tbody>

I am trying to do the same with twig:

<tbody>
    {% for row in categories %}
      <tr>
        {% for cell in row %}
           <td> </td>
        {% endfor %}
      </tr>
    {% endfor %}
</tbody>

Can anyone please tell me what should i put between to get the result?

1 Answer 1

1

It's just as easy as use a variabe:

<tbody>
    {% for row in categories %}
      <tr>
        {% for cell in row %}
           <td>{{ cell }}</td>
        {% endfor %}
      </tr>
    {% endfor %}
</tbody>

Or if you want to use the key too:

<tbody>
    {% for row in categories %}
      <tr>
        {% for key, cell in row %}
           <td> </td>
        {% endfor %}
      </tr>
    {% endfor %}
</tbody>

And if cell is an array you can just use cell.yourkey cell.anotherkey.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.