[prev in list] [next in list] [prev in thread] [next in thread]
List: smarty-general
Subject: Re: [SMARTY] plugin & assign weirdness
From: Luc Saint-Elie <luc () saint-elie ! com>
Date: 2004-02-16 7:34:11
Message-ID: 837A0ECF-6052-11D8-9B1A-00039398BC84 () saint-elie ! com
[Download RAW message or body]
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}
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic