RFC: new type of block function
| From: | Greg Stark | Date: | Mon, 12 May 2003 20:38:49 +0000 |
| Subject: | RFC: new type of block function | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-9532@lists.php.net to get a copy of this message | ||
I think there's a problem with the html_options function and similar functions
in that it forces the programmer to do part of the layout. There are also a
lot of missing functions that don't exist, largely because there's no way
around this same issue.
In a select list there are two sets of things, the option values and the text
that's presented to the user in the select list. The former really should be
provided by the php backend code, and the latter should really be provided by
the template.
Code that uses the existing html_options function has to provide the text of
the options in the associative array (or in parallel arrays -- flashbacks to
Fortran plague me still!).
$smarty->assign('languages', array('en' => English, 'fr' =>
'French'));
This forces the "English" and "French" which are texts that appear on the web
site to be sent from the php code. The template gets no opportunity to control
the formatting of these.
The situation is even more obvious if the data being presented is some sort of
textual description of a compound object:
foreach($products as $product) {
options[$product->id] = describe_product($product);
}
$smarty->assign('options', $options);
The code in describe_product really really ought to be in the template.
I would prefer to write this as:
$smart->assign('products', $products);
and then have the template do something like:
{select name=foo from=$products item=product key=id}
{$product->model_number}: {$product->name} ({$product->colour})
{/select}
However this require the ability to add foreach-like block functions via the
plugin mechanism. Currently plugins cannot do this.
I can think of lots of other uses for foreach-like plugins, but this is the
clearest case I've run into so far.
--
greg