Re: [SMARTY] RFC: new type of block function

From: Date: Mon, 12 May 2003 21:19:30 +0000
Subject: Re: [SMARTY] RFC: new type of block function
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-9533@lists.php.net to get a copy of this message
On Mon, May 12, 2003 at 04:38:49PM -0400, Greg Stark wrote: > > 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. the cvs-version of smarty allows block-plugins to control repition of the content between {block} and {/block}. together with manipulating your item variable from within the plugin and string-replacement of $content before it is returned this is all you need to build a {select} as the one you want above. see the short thread at http://marc.theaimsgroup.com/?l=smarty-dev&m=105084561708448&w=2 for an introduction. greetings messju > -- > greg

« previous php.smarty.general (#9533) next »