Answer the question
In order to leave comments, you need to log in
How to send array from PHP and display it in tpl template using JS in dynamically created fields?
PHP has an array:
Array
(
[0] => Array
(
[0] => 1994-02-12
[1] => 12021
[2] => 1994-03-12 00:00:00
[3] => 6.00
[4] => 60.00
)
[1] => Array
(
[0] => 1994-01-25
[1] => 25011
[2] => 1994-03-25 00:00:00
[3] => 25.00
[4] => 5.00
)
[2] => Array
(
[0] => 2019-09-03
[1] => 3092
[2] => 2019-10-03 00:00:00
[3] => 309.00
[4] => 39.00
)
[3] => Array
(
[0] => 1963-04-13
[1] => 13041
[2] => 1963-05-13 00:00:00
[3] => 1304.00
[4] => 134.00
)
[4] => Array
(
[0] => 1964-07-25
[1] => 25071
[2] => 1964-09-25 00:00:00
[3] => 2507.00
[4] => 257.00
)
)
$smarty->assign('arrInvFix', $arrInvFix);
{if !empty($arrInvFix)}
{literal}
<script type="text/javascript">
var fixInvoice = new Array({$arrInvFix});
console.log(fixInvoice);
</script>
{/literal}
{/if}
Answer the question
In order to leave comments, you need to log in
{if !empty($arrInvFix)}
<script type="text/javascript">
//Формируем из массива JSON, который потом парсим через JSON.parse.
let fixInvoice = JSON.parse("{htmlspecialchars(json_encode($arrInvFix))}");
console.log(fixInvoice);
</script>
{/if}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question