Re: [SMARTY] need help with executing own function

From: Date: Tue, 18 Jan 2005 14:49:30 +0000
Subject: Re: [SMARTY] need help with executing own function
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-12169@lists.php.net to get a copy of this message
On Tue, Jan 18, 2005 at 04:19:53PM +0800, zuhaimi zainal wrote: > hi folks, > > i've just started using smarty. i think its great but i do find some > difficulty adjusting to it. right now i'm stuck. i'm sure its quite a > simple one so please bear with me. > > what do i need to do in smarty so that i can execute my own function > on a template var? > > take a look at this situation.. let say in my template: > --begin code-- > <td>Car Type: </td><td>{$car->car_type}</td> > <td>Displacement: </td><td>{$car->car_cc}</td> > --end code-- > > $car is being assign value from a db query result (car_type, car_cc > are table columns) > > now, car_type are integers.. it does not contain the actual car type. > before i use smarty, this can easily done by creating a function to > translate the car_type to its respective type. ie: car_type 1 is for > sedan, car_type 2 is for hatchback etc etc.. like this > --begin code-- > <td>Car Type: </td><td><?php echo getCarType($car->car_type) > ?></td> > --end code-- > with the function getCarType returning the actual car type. > > but how do i do it (the getCarType function) now in the template with > smarty? fyi, all my functions are in one separate file. you can either compute the car_type's name for each element in php where you assign $car, or you write a modifier. see: http://smarty.php.net/manual/en/language.modifiers.php on modifiers HTH messju > tia, > zuhaimi > > -- > When you signup for PayPal, you can start accepting credit card > payments instantly. As the world's number one online payment service, > PayPal is the fastest way to open your doors to over 40 million member > accounts worldwide. > Best of all, it's completely free to sign up! > To sign up or learn more, click here: > https://www.paypal.com/row/mrb/pal=ET694X3JAP9X2 > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.smarty.general (#12169) next »