Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

I want to pass an array to smarty

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Mystic`
Smarty n00b


Joined: 30 Apr 2003
Posts: 2

PostPosted: Wed Apr 30, 2003 12:47 am    Post subject: I want to pass an array to smarty Reply with quote

Hi there.
First smarty is great ! Smile
Second : i've a prob with it Rolling Eyes Shocked

I want print some news, si i make an array with this :

Code:
$i=0;

WHILE(($get_news = mysql_fetch_object($req)) and ($i <= 3)) // only 4 news
{
  $news[$i][id] = $get_news->id;
  $news[$i][name] = $get_news->name;
  $news[$i][date] = date("m/d/y H:i",$get_news->date);
  $news[$i][titre] = $get_news->titre;
  $news[$i][text] =  replace_balises($get_news->text);
  $i++;
}


That's give me a array, and i want to pass this array in smarty.
I've try
Code:

WHILE(($get_news = mysql_fetch_object($req)) and ($i <= 3)) //on veut que 4 news
{
  $date = date("m/d/y H:i",$get_news->date);
  $text = replace_balises($get_news->text);
  $smarty->assign("news[$i]",array("$get_news->id",
                                   "$get_news->name",
                                   "$date",
                                   "$get_news->titre",
                                   "$text"
                                   )
                 );
  $i++;
}

and
Code:

$smarty->assign("news","$news");


but both dont work...
i've search in faq and manual, i dont find how to put $news php's variable into $news smarty's variable with the same structure.

Help.

Jeremy

PS: var_dump of $news can be see here : http://mystic.phpnet.org/tmp/var_dump.htm
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Apr 30, 2003 12:54 am    Post subject: Reply with quote

Try this:

::EDIT::

Code:
WHILE(($get_news = mysql_fetch_object($req)) and ($i <= 3)) //on veut que 4 news
{
  $date = date("m/d/y H:i",$get_news->date);
  $text = replace_balises($get_news->text);
  $news[]    =     array("$get_news->id",
                                   "$get_news->name",
                                   "$date",
                                   "$get_news->titre",
                                   "$text"
                                   );
  $i++;
}
$smarty->assign_by_ref('news', $news);


ps. bonjour!
Back to top
View user's profile Send private message
Mystic`
Smarty n00b


Joined: 30 Apr 2003
Posts: 2

PostPosted: Wed Apr 30, 2003 11:13 am    Post subject: yep it's work ! Reply with quote

that work fine ! thanks a lot boots ! Smile

Helloooooooooooooooooooooooooooooooooo
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP