I am retrieving a smarty array ‘data’ and I want to store it inside a javascript variable ‘store’ :
{if isset({$data})}
<script type="text/javascript">
var store = {ldelim}{rdelim};
{foreach from=$data key=k item=v}
var index = {$k};
store.index = {$v};
{/foreach}
alert(store);
</script>
{/if}
but I have no alert output. Someone could help ?
Rmk : I need that to run this
$("input").each(function(index) {
return this.value = store.index;
});
Edit : Inthe source code, I get var store = {};
Instead of going the long and very hard to read way of trying to create a javascript object/array via Smarty, try this;
and in the template;
So, we are letting PHP create a valid javascript object for us and assign that string to smarty, which simply created a variable and assigns that string.