Page 1 of 1

creating an array with user defined tags

Posted: Thu Oct 21, 2010 2:11 am
by blackhawk
what is the proper format in creating a 'basic' associative array within a user defined tag.  for example, if i have this foreach in my content page...

Code: Select all

{foreach from=$nodelist item=node}
<a href="{$node->url}" {if $node->current}class="current"{/if} 
>{$node->menutext}</a> |
{/foreach}
then what are the format requirements for building the associative array in the user define tag, and how does $nodelist and node relate to the user define tag if I have an associative array?

All I know is that I want this..

Code: Select all

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
)
to connect to my foreach loop in my content section on page.

thanks for any advice!

Re: creating an array with user defined tags

Posted: Thu Oct 21, 2010 7:16 am
by bess

Code: Select all

{foreach from=$nodelist item=node}
<a href="{$node->url}" {if $node->current}class="current"{/if} 
>{$node->menutext}</a> |
{/foreach}
it's not only an array, but an array of object.

In your UDT

Code: Select all

$foo = array();

for ($i=0, $i<10, $i++)
{
   $bar = new stdclass;
   $bar->url = 'http://www.cmsmadesimple.org';
   $bar->current= false;
   $bar->menutext= 'AZEaze';

   $foo[] = $bar;
}

//save $foo for your gabarit
global $gCms;
$smarty = &$gCms->GetSmarty();
$smarty->assign("nodelist",$foo);
done

Re: creating an array with user defined tags

Posted: Sun Oct 24, 2010 6:07 pm
by Dr.CSS
From my understanding the $node-> stuff is only available in the menu manager, you may have to call the menu manager module into the UDT to use these...

Re: creating an array with user defined tags

Posted: Mon Oct 25, 2010 1:21 pm
by blackhawk
thank you so much!  appreciate the good insights!  I got my arrays working with the help.