creating an array with user defined tags

General project discussion. NOT for help questions.
Post Reply
blackhawk
Power Poster
Power Poster
Posts: 280
Joined: Mon Oct 20, 2008 6:07 pm

creating an array with user defined tags

Post 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!
Last edited by blackhawk on Thu Oct 21, 2010 2:14 am, edited 1 time in total.
bess
Language Partners
Language Partners
Posts: 282
Joined: Thu Dec 18, 2008 9:37 am

Re: creating an array with user defined tags

Post 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
Last edited by bess on Thu Oct 21, 2010 7:19 am, edited 1 time in total.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: creating an array with user defined tags

Post 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...
blackhawk
Power Poster
Power Poster
Posts: 280
Joined: Mon Oct 20, 2008 6:07 pm

Re: creating an array with user defined tags

Post by blackhawk »

thank you so much!  appreciate the good insights!  I got my arrays working with the help.
Post Reply

Return to “General Discussion”