Not working macro foreach

Notice: This thread is very old.
interconn
Member | 2
+
0
-

Hello,
I'm feeling like getting crazy: I try to use a foreach-Macro or a foreach-loop but I can't get the conten I want.

Here my php-Part:

$parameters = ['ticketResponsible' => [['klarname' => 'Person', 'id' => 'Test'],['klarname' => 'Person2', 'id' => 'Test2']]];

$latte->render(ACT_DIR.'/inc/templates/Aufwandsanalyse.latte', $parameters);

And in my template

<select class="form-control">
	<option n:foreach="$ticketResponsible as $item" value="{$item->id}">{$item->klarname}</option>
</select>
<select class="form-control">
	{foreach $ticketResponsible as $item}
		<option value="{$item->id}">{$item->klarname}</option>
	{/foreach}
</select>

Both loops generate no output… What am I doing wrong, I'm somehow lost.

Thanks for your help

norbe
Backer | 405
+
+1
-

I see you are using arrays as objects. As you probably do not use tracy, php throws some errror and goes down without any related info.

interconn
Member | 2
+
0
-

Good morning,

I'm using Tracy but the warning thrown doesn't help at all. But your comment on objects did.
Actually it's quite simply:

<option n:foreach="$ticketResponsible as $item" value="{$item[id]}">{$item[klarname]}</option>

did solve the issue.
I expected a simple solution like that but at least for me it was not obviously explained in the docs.

Thanks

CZechBoY
Member | 3608
+
0
-

@interconn What is not clear in the doc?
https://latte.nette.org/en/#… this looks same as your code.