E
E
Eobard Thawne2019-06-16 22:12:38
symfony
Eobard Thawne, 2019-06-16 22:12:38

How to display names from an array separately from each other?

Hello everyone, in general, what is the problem. I'm getting data from an array...

$names = array_column($data['data']['builder'], 'name');
        $name = implode(', ', $names);
return $this->render('builders/index.html.twig', [ 'name' => $name ]);

... and everything works, but it's all output in this way. 5d069438b916f720852983.png
How to make it so that for each name a separate row is created in the table, and so on. In general, what would each name be displayed separately?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2019-06-16
@vexgg

Direct answer to the question:
You pass the string that you collected from the array into the template.
1. Pass an array at once

$this->render('builders/index.html.twig', ['names' => $names])

2. And on the Twig side, arrange the data as needed in the layout in a loop
Why do you work with arrays? Maybe it's better to collect the objects of the developers and also scatter them in the loop in the request? Without arrays

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question