Perad Posted February 21, 2007 Share Posted February 21, 2007 Can someone quickly demonstrate how i would edit the below code to use a function. When i try to use functions i cannot select my template variables from within the function. Without the function i can use the following without a problem $smarty->assign("postdate", $date); $smarty->assign("title", $title); $smarty->assign("author", $author); $smarty->assign("authorid",$profileid); $smarty->assign("content",$news); $smarty->assign("id",$id); However, with a function the $smarty->assign cannot access the variables. How do i change either the assign path or the function so it can look inside my function get the relevant information. Full code function newfunction() { global $dbc; $query = "SELECT * FROM news ORDER BY postdate DESC LIMIT 5"; $result = mysql_query ($query); while ($row = mysql_fetch_assoc ($result)) { $date[] = $row['postdate']; $title[] = $row['title']; if ($row['newsinbrief'] == NULL) { $news[] = $row['newstext']; } else { $news[] = $row['newsinbrief']; } $author[] = $row['author']; $profileid[] = $row['author_id']; $id[] = $row['id']; include_once("../textilephp/Textile.php"); $text[] = $news; $textile = new Textile; $processednews[] = $textile->process($text); } } $smarty->assign("postdate", $date); $smarty->assign("title", $title); $smarty->assign("author", $author); $smarty->assign("authorid",$profileid); $smarty->assign("content",$news); $smarty->assign("id",$id); $smarty->display('indexmain.tpl'); Link to comment https://forums.phpfreaks.com/topic/39468-smarty-functions-and-smarty-assign/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.