For Programmers: Free Programming Magazines  


Home > Archive > PHP Smarty Templates > January 2005 > Re: [SMARTY] need help with executing own function









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [SMARTY] need help with executing own function
Messju Mohr

2005-01-18, 4:09 pm

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

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com