Keval Bhogayata Posted February 19, 2018 Share Posted February 19, 2018 I am passing some of the variables to the .tpl file from php file using concatenation as given below: while($row=mysqli_fetch_assoc($run_field)) { foreach($row as $rows) { $response_field = array( 'extraVariable1'.$i => $row['id'], 'extraVariable2'.$i => $row['name'], ); } $finalarray_field=$finalarray_field+$response_field; $i++; } return array( 'tabOverviewReplacementTemplate' => $templateFile, 'templateVariables' => $finalarray_field, ); Now, I want to show this values in .tpl file. Is there any way so that I can print all the variables using loops (so that I should not have to write repeatedly as {extraVariable11}, {extraVariable12},.... and so on). Link to comment Share on other sites More sharing options...
sentq Posted February 19, 2018 Share Posted February 19, 2018 this code is illogical, invalid in few ways, try to apply the following: $finalarray_field = array(); while($row = mysqli_fetch_assoc($run_field)) { $finalarray_field[] = array( 'extraVariable1' => $row['id'], 'extraVariable2' => $row['name'], ); } return array( 'tabOverviewReplacementTemplate' => $templateFile, 'templateVariables' => array("finalarray" => $finalarray_field), ); then in your template file you display it using the following code: {foreach item=row from=$finalarray} <div>Variable #1: {$row.extraVariable1}</div> <div>Variable #2: {$row.extraVariable2}</div> <div>----------------------------------</div> {/foreach} 1 Link to comment Share on other sites More sharing options...
Keval Bhogayata Posted February 20, 2018 Author Share Posted February 20, 2018 13 hours ago, sentq said: this code is illogical, invalid in few ways, try to apply the following: $finalarray_field = array(); while($row = mysqli_fetch_assoc($run_field)) { $finalarray_field[] = array( 'extraVariable1' => $row['id'], 'extraVariable2' => $row['name'], ); } return array( 'tabOverviewReplacementTemplate' => $templateFile, 'templateVariables' => array("finalarray" => $finalarray_field), ); then in your template file you display it using the following code: {foreach item=row from=$finalarray} <div>Variable #1: {$row.extraVariable1}</div> <div>Variable #2: {$row.extraVariable2}</div> <div>----------------------------------</div> {/foreach} I came across some of the mistakes I have made in syntax. Thank you. Link to comment Share on other sites More sharing options...
Recommended Posts