I have a nested array that I am passing as templateVar.
setTemplateVars(['details' => $arr])
The array($arr) is
[0] => [
["key1"]=>value1
["key2]=>value2
]
[1]=>[
["key1"]=>value1
["key2]=>value2
]
.
.
.
All arrays have same keys.
I have tried both updates mentioned in How to show array in email template file?
In the template file, I'm trying to use it as -
<?php foreach($details as $detail) : ?>
<p>{{trans ' %val' val=$detail.key1}}</p>
<?php endforeach; ?>
I cannot pass it as a string as the array can be an array of 100s of arrays with same keys.
-
you can use foreach loopfmsthird– fmsthird2019年04月02日 21:45:41 +00:00Commented Apr 2, 2019 at 21:45
-
Have you did it?Dhaduk Mitesh– Dhaduk Mitesh2019年11月13日 04:54:12 +00:00Commented Nov 13, 2019 at 4:54
1 Answer 1
Providing you an static way to get the specific value of array key. You can pass it like this:
setTemplateVars(['details' => $arr[0]->key1]) //get key1 value from array 0
setTemplateVars(['details' => $arr[1]->key1]) //get key1 value from array 1
Using foreach loop
(削除) foreach($arr as $detail){
setTemplateVars(['details'=> $detail["key1"]);} (削除ここまで)
<?php foreach($details as $detail) : ?>
<p>{{trans ' %val' val = $detail["key1"]}}</p>
<?php endforeach; ?>
-
Can you elaborate how to use foreach? I've tried - foreach($details as detail): <p>$detail.key1</p> - This doesn't workcoderGeek– coderGeek2019年04月02日 23:00:35 +00:00Commented Apr 2, 2019 at 23:00
-
-
How to use this is the template file?coderGeek– coderGeek2019年04月02日 23:53:49 +00:00Commented Apr 2, 2019 at 23:53
-
can you update your question with your code in the template filefmsthird– fmsthird2019年04月03日 00:04:10 +00:00Commented Apr 3, 2019 at 0:04
-
can you try this
<?php foreach($details as $detail) : ?> <p>{{trans ' %val' val = $detail["key1"]}}</p> <?php endforeach; ?>fmsthird– fmsthird2019年04月03日 02:56:02 +00:00Commented Apr 3, 2019 at 2:56