2

I'm currently working on a Symfony 2.7 and I have in my controller 3 arrays. But I want to show all of this 3 arrays in one array in the view. Someone know

You can see the return in my controller here with my 3 arrays (entities, tabStatus and tabName) I can't merge the arrays in one.

return $this->render('testAdminBundle:Default:showBt.html.twig', 
array('entities' => $entities, 'tabStatus' => $tabStatus, 'tabName' => $tabName));

And here my view :

   <div class="bs-example">
        <table class="table table-striped">
          <thead>
            <tr>
              <th>Name</th>
              <th>Login</th>
              <th>Status</th>
              <th>Items</th>
              <th>Actions</th>
            </tr>
          </thead>
          <tbody>
          {% for value in entities %}
            <tr>
              <td></td>
              <td>{{ value.login }}</td>
              <td></td>
              <td>{{ value.items }} / 2400</td>
              <td></td>
            </tr>
            {% endfor %}
          </tbody>
        </table>
      </div><!-- /example -->
      <br>

You can see in my view i show only the array entites because I can't put the 2 others arrays in the for. It is event possible to do something like this : {% for value1 in entities, value2 in tabStatus, value3 in tabName %} ? Or maybe I need to use key in twig ?

Thanks per advance !

PokeRwOw

2
  • Maybe you should rebuild 3 arrays $entities, $tabStatus, $tabName to one array? Commented Aug 4, 2015 at 20:00
  • the arrays have the same key? The same length? So you want to avoid to make three different loop with the same html code? Commented Aug 5, 2015 at 4:55

2 Answers 2

1

Try something like this:

{% for key, value in entities %}
    {{ value }} {{ tabStatus[key] }} {{ tabName[key] }}
{% endfor %}
Sign up to request clarification or add additional context in comments.

Comments

0

why you can't merge them into one? did you try array_merge_recursive instead of array_merge? else Alexander Micklewright solution should be what you want. or the use of multiple foreach and use includes to avoid duplicated codes.

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.