jquery - Getting javascript var from database record in Smarty -
i'm working on prestashop page file extension ".tpl". javascript code auto complete this:
var currencies = [ { value: 'afghan afghani', data: 'afn' }, { value: 'albanian lek', data: 'all' }, { value: 'algerian dinar', data: 'dzd' }, { value: 'european euro', data: 'eur' }, { value: 'angolan kwanza', data: 'aoa' }, { value: 'east caribbean dollar', data: 'xcd' }, { value: 'vietnamese dong', data: 'vnd' }, { value: 'yemeni rial', data: 'yer' }, { value: 'zambian kwacha', data: 'zmk' }, { value: 'zimbabwean dollar', data: 'zwd' },];
while have foreach
example below:
{foreach from=$currencies item=currency} {$currency.name} {$currency.code} {/foreach}
how output currencies
value foreach
? tried code:
var currencies = [ {foreach from=$currencies item=currency} { value: '{$currency.name}', data: '{$currency.code}' }, {/foreach},];
you can use json_encode
output php array javascript
this javascript code in tpl
var currencies = json.parse('{$currencies|json_encode}');
{$currencies|json_encode}
output this
[{ value: 'afghan afghani', data: 'afn' }, { value: 'albanian lek', data: 'all' }, { value: 'algerian dinar', data: 'dzd' }, ...]
this output passed javascript function json.parse
transform output string javascript object
Comments
Post a Comment