Some changes to Smarty
| From: | Piotr Klaban | Date: | Thu, 14 Nov 2002 10:48:33 +0000 |
| Subject: | Some changes to Smarty | ||
| Groups: | php.smarty.dev | ||
| Request: | Send a blank email to php-smarty-dev+get-333@lists.php.net to get a copy of this message | ||
Hi,
I have created some new Smarty plugins, and two patches to other smarty
plugins. There are too many lines to post it here, that is why I made
it available at
http://www.klaban.torun.pl/patches/smarty/
There are available the following plugins:
1. Assign smart variables from PHP eval'ed values:
function.assign_php.php
function.eval_php.php
Example of usage:
{assign_php var="colorarr"
value="array('#FFFFFF','#AAAAAA','#BBBBBB','#C0C0C0')"}
{eval_php assign="coloridx" var="rand(0,3)"}
<font color="{$colorarr.$coloridx}">Test</font>
2. Localization (changed plugins):
modifier.date_format.php (not new plugin, only patched)
function.html_select_date.php (new 'locale_time' parameter)
{$smarty.now|date_format:"%e %B %Y %T":"":"PL"} // date in Polish
{$smarty.now|date_format:"%e %B %Y %T":"":"DE"} // date in German
^^^^ - additional locale argument
Select date in Polish with Polish field order:
{html_select_date locale_time="pl" field_order="DMY"}
Select date in English (if web server locale is not 'en'):
{html_select_date locale_time="en"}
3. New plugins - presenting arrays as a set of INPUT HTML elements
either radio boxes or checkbox-es (similar to html_options):
function.html_radio.php
function.html_checkbox.php
Example usage (similar to html_options; new 'name' parameter):
{html_radio name="test-radio[]" values=$vals
selected=$selected output=$output}
{html_checkbox name="test-checkbox[]" values=$vals
selected=$selected output=$output}
gives e.g.:
<input type="radio" name="test-radio[]" value="1" /> A<br>
<input type="radio" name="test-radio[]" value="2"
checked="checked" /> B<br>
<input type="radio" name="test-radio[]" value="3"
checked="checked" /> C<br>
<input type="checkbox" name="test-checkbox[]" value="1" />
A<br>
<input type="checkbox" name="test-checkbox[]" value="2"
checked="checked" /> B<br>
<input type="checkbox" name="test-checkbox[]" value="3"
checked="checked" /> C<br>
You can also add all_extra parameter. E.g. all_extra="onClick='...'"
4. APPENDING VALUES (function.append.php and function.strcat.php)
Documentation is not clear in the Chapter 13, about what 'append'
method can do. I thought that it is a mthod for concatenation,
like a dot in PHP. What I realize is that append makes an ARRAY
and appends new value as a last item of the array.
BTW in append_by_ref in Chapter 13 there is a spell mistake -
Technical note talks about assign_by_append() while it should be
append_by_ref(), and example is 'void assign()' while it should be
append_by_ref().
Last two new plugins:
function.append.php - calls $smarty->append() on a given variable
function.strcat.phps - adds new value to the end of the string variable
Example usage:
{assign var="name" value="Smarty"}
{strcat var="name" value=" Template"}
{$name}
gives output: 'Smarty Template'
Best regards,
--
Piotr Klaban