Re: [SMARTY] plugin & assign weirdness
| From: | Luc Saint-Elie | Date: | Mon, 16 Feb 2004 07:34:11 +0000 |
| Subject: | Re: [SMARTY] plugin & assign weirdness | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-10953@lists.php.net to get a copy of this message | ||
Le 16 févr. 04, à 03:34, David Spreekmeester a écrit :
Hello, Writing a function plugin for Smarty, I keep on running in to the problem of using assign() to set a template variable. This doesn't seem to work as it should if I understand the manual correctly. Returning a value from the function works fine, but when I try to assign a variable to the template ($smarty->assign), nothing comes through in the output nore in the debug console.David, I'm not certain to understand the question perfectly but, I use polug ins this way: <?php /* * Smarty plugin * -------------------------------------------------------------
* File: function.getedito.php * Type: function * Name: getedito* Purpose: Afiche le dernier edito en ligne * ------------------------------------------------------------- */ function smarty_function_getedito($params, &$smarty) { $dsn = "mysql://".$smarty->user.":".$smarty->pass."@".$smarty-
host."/".$smarty->db_name; .. PEAR initialization$sql = "SELECT * FROM ".$smarty->edito_tbl." WHERE enligne ='1'"; $result = $smarty->db->query($sql); if (DB::isError($result)) { die ($result->getMessage()); } while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) { $donnees[] = array( 'idedito' =>$row['idedito'], 'datesaisie' =>$row['datesaisie'], 'titre' =>$row['titre'], 'texte' =>$row['texte'] ); } $result->free(); $smarty->assign('edito', $donnees); } ?> And in the *.tpl file : {getedito} {section name=masec loop=$edito} {$edito[masec].titre}... and so on {/section}