Twig Template For loop Results
Posted
by
user981480
on Stack Overflow
See other posts from Stack Overflow
or by user981480
Published on 2012-10-07T21:34:16Z
Indexed on
2012/10/07
21:37 UTC
Read the original article
Hit count: 288
I am trying to print out a the contents of an array but am not getting the expected results. any help is much appreciated:
PHP code:
$list[1]['first_name'] = 'Joe';
$list[1]['last_name'] = 'Smith';
$list[2]['first_name'] = 'John';
$list[2]['last_name'] = 'brand';
$data = array(
'customer' => $list
);
echo $template->render($data);
Template Markup:
<html>
<head><title>My first Twig template!</title></head>
<body>
{% for person in customer %}
{{ person.first_name }}
{% endfor %}
</body>
RESULTS:
Array ( [first_name] => Joe [last_name] => Smith )
first_name
Joe
Array ( [first_name] => John [last_name] => brand )
first_name
John
© Stack Overflow or respective owner