How to set up a smarty array in a template?
Posted: Thu Aug 21, 2008 2:39 pm
Hi
I am trying to pass the values of a smarty loop into a javascript array. I suspect I may have to first pass the values to a Smarty array and then assign that to the javascript array but I am unsure how to declare a smarty variable as an array. This has to happen in a template because I am using smarty to dig out the data. i.e.
var data = new Array();
{foreach from=$cgsimple->get_children('$page_alias','0') item='child'}
{assign var='smarty_data' value=$cgsimple->get_page_content($child.alias,'Photo_Name')}
data = {$smarty_data};
{/foreach}
{literal}
// the values of the javascript array data are used in the function below
window.addEvent('domready', function() {
var myShow = new Slideshow.KenBurns('show', data, { captions: true, controller: true, delay: 4000, duration: 2000, height: 515, hu: '/uploads/filepath/', width: 774 });
})
{/literal}
So instead of having data = {$smarty_data}; in the loop I presume I need to use a Smarty arry to capture the data and then pass it to the javascript data array after the loop has finished.
All and any help much appreciated.
I am trying to pass the values of a smarty loop into a javascript array. I suspect I may have to first pass the values to a Smarty array and then assign that to the javascript array but I am unsure how to declare a smarty variable as an array. This has to happen in a template because I am using smarty to dig out the data. i.e.
var data = new Array();
{foreach from=$cgsimple->get_children('$page_alias','0') item='child'}
{assign var='smarty_data' value=$cgsimple->get_page_content($child.alias,'Photo_Name')}
data = {$smarty_data};
{/foreach}
{literal}
// the values of the javascript array data are used in the function below
window.addEvent('domready', function() {
var myShow = new Slideshow.KenBurns('show', data, { captions: true, controller: true, delay: 4000, duration: 2000, height: 515, hu: '/uploads/filepath/', width: 774 });
})
{/literal}
So instead of having data = {$smarty_data}; in the loop I presume I need to use a Smarty arry to capture the data and then pass it to the javascript data array after the loop has finished.
All and any help much appreciated.