0

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.

2
  • you can use foreach loop Commented Apr 2, 2019 at 21:45
  • Have you did it? Commented Nov 13, 2019 at 4:54

1 Answer 1

0

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; ?> 
6
  • Can you elaborate how to use foreach? I've tried - foreach($details as detail): <p>$detail.key1</p> - This doesn't work Commented Apr 2, 2019 at 23:00
  • check updated ans Commented Apr 2, 2019 at 23:20
  • How to use this is the template file? Commented Apr 2, 2019 at 23:53
  • can you update your question with your code in the template file Commented Apr 3, 2019 at 0:04
  • can you try this <?php foreach($details as $detail) : ?> <p>{{trans ' %val' val = $detail["key1"]}}</p> <?php endforeach; ?> Commented Apr 3, 2019 at 2:56

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.