Re: [SMARTY] modifier_string_format in 2.5.0-RC1
| From: | Monte Ohrt | Date: | Thu, 06 Mar 2003 21:36:21 +0000 |
| Subject: | Re: [SMARTY] modifier_string_format in 2.5.0-RC1 | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 | Groups: | php.smarty.dev php.smarty.general |
| Request: | Send a blank email to php-smarty-dev+get-896@lists.php.net to get a copy of this message | ||
I see what is wrong. Look at the examples in the manual. Here is how
string_format works:
{$number|string_format:"%.2f"}
Notice the formatting is in the parameter, not in the variable. You are
trying to do this:
{"test %s"|string_format:"hello"}
when it actually works like this:
{"hello"|string_format:"test %s"}
I agree the implementation isn't too flexible because you can't give it
more than one value to format. It should probably work the other way
around like this:
{"%s foo %s foo %s"|string_format:$val1:$val2:$val3}
But that breaks backward compatability. Thoughts?
Monte
On Thu, 2003-03-06 at 09:59, Paul Lockaby wrote:
> Monte Ohrt wrote:
> > You're right, this is fixed in CVS for the official 2.5.0 release. This
> > was erroneously swapped in CVS, so it was right some time back.
> >
> > Thanks
> > Monte
> >
>
> Except that the version you just committed doesn't work, atleast not for
> me! My script looks like this:
>
> {assign var="foo" value="test %s"}
> {assign var="bar" value="hello"}
> {$foo|string_format:$bar}
>
> That works with the previous version, but not with the most recently
> committed version. However, I find that the best way to use sprintf is
> to register it as a modifier like so:
>
> $smarty->register_modifier("string_format","sprintf");
>
> Then you can pass as many arguments to it as you want, just like if you
> had direct access to it.
>
> ~Paul
--
Monte Ohrt <monte@ispi.net>