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},]; 

http://i.stack.imgur.com/dhygl.jpg

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

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -