Re: [SMARTY] Thousands separator and nl2br()
| From: | Ben Curtis | Date: | Sat, 13 Jul 2002 16:06:57 +0000 |
| Subject: | Re: [SMARTY] Thousands separator and nl2br() | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-5278@lists.php.net to get a copy of this message | ||
You can easily filter your variables through php functions such as
{$number|number_format} (for the , separator in numbers) and
{$sometext|nl2br}.
On Sat, Jul 13, 2002 at 01:08:04PM +0100, Simon Lee wrote:
> Hi folks,
>
> Bit of a newbie to Smarty (used FastTemplate before...where have I
> been?!?!? :P), but I hope you can help me out on a couple of easy
> problems.....as it is the weekend and all that!
>
> I pull out results from a db into an assoc array like so ($dba is my db
> abstraction class, $result = handle from executing the SQL query):
>
> ---------------8<-------------------------------
>
> while ( $row = $dba->fetch_assoc($result) ) {
> $output[] = $row;
> }
>
> ---------------8<-------------------------------
>
> $output can then be used by {section} in the template to loop through
> the rows....
>
> (1) Is there a way to format a number e.g. 100000 in the template with a
> thousands separator so that it appears 100,000?
> Now I know I can build up the array $output by explicitly specifying the
> format of each field, but I'm in a lazy mood! ;)
>
> (2) Another problem relates to formatting in the template file, where I
> have a text field with "\n" in it to represent newlines, and again, if I
> was building $output explicitly I could just use nl2br($var)......is it
> possible to do this in a template file?
>
> Thanks!
>
> _________
> Simon Lee
>
> --- LeapForward ---
> creative intelligence for the networked economy
>
> 167a Clapham High Street, London SW4 7SS
> t: +44(0)70 9234 1503
> f: +44(0)70 9234 1787
>
> e: simon.lee@leapforward.net
> www.leapforward.net
>
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php