Re: [SMARTY] Unofficial new feature patch for Smarty 2.1.1
| From: | Stealth Dave | Date: | Tue, 21 May 2002 00:38:31 +0000 |
| Subject: | Re: [SMARTY] Unofficial new feature patch for Smarty 2.1.1 | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-4318@lists.php.net to get a copy of this message | ||
On Mon, 2002-05-20 at 15:53, Monte Ohrt wrote:
> Dave,
>
> I commend your efforts! However, Smarty already does most of these things:
>
> 1) Block capture.
>
> How is this any different then the {capture} function already in Smarty?
Good point. I guess I should read the documentation better. :)
I think my confusion on this one came from the example in the
documentation. Somehow that gave me the impression that {capture} only
works on {include} functions, which it obviously does not. Perhaps a
slightly different example in the docs would help? Or maybe it's just
me.
> 2) For loop
>
> Smarty's {section} loop can already accomodate everything you are doing
> here:
>
> {section name=counter loop=10 step=3}
> I am {$smarty.section.counter.index} years old!<br>
> {/section}
Could that example be added to the documentation? In the documentation
for {section}, all the examples show {section} with loop being an
array. The attributes table for {section} states that loop must be a
variable name. Since all the examples show loop as an array, I assumed
that {section} could only be used on arrays. Had I known this, I
definitely would have saved myself a lot of trouble and just used
{section} (it took me several days to figure out how to add this
functionality to Smarty).
> 3) function count array
>
> You can already do this in Smarty.
>
> There were {$smarty.get|@count} values submitted through GET!
>
> If you feel inclined to assign something:
> {assign var="SmartyInternal" value=$smarty|@count}
Ah! I missed the caveat of using the @ symbol to affect an array rather
than each value in the array.
> 4) Left Trim:
>
> This is shorthand for {$var|regex_replace:"!^\s+!":""}
> This could be something handy to put in the repository.
>
> 5) Right Trim
>
> This is shorthand for {$var|regex_replace:"!\s+$!":""}
> This could be something handy to put in the repository.
>
> 6) Trim
>
> You could use php trim, or make a wrapper to it (probably what this is?)
> {$var|trim}
Yes, all the trim functions are pretty much just wrappers on the PHP
functions they represent. Still, I find them pretty useful. Besides,
it's a little easier to remember {$var|ltrim} than
{$var|regex_replace:"!^\s+!":""} (I've never been very good with regular
expressions).
> 7) URL Encode
>
> Smarty already does this:
>
> {$TestString|escape:"url"}
We'll just add this to the massive rounds of 'RTFM'. ;) Still, it was a
good exercise. Maybe in the future I can come up with something that's
actually useful!
- Dave
> --
> Monte Ohrt <monte@ispi.net>
> Director of Technology, ispi Inc.
>
--
David E. Still phone:818.980.6909
dave@stilldesigning.com http://www.stilldesigning.com