Preprocessing string concatenations

From: Date: Fri, 19 Jul 2002 20:18:08 +0000
Subject: Preprocessing string concatenations
Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-211@lists.php.net to get a copy of this message
Not sure if this is in the realm of Smarty processing or application design but heres something to consider. Lets say we have an array where each element is named sequentially, but not necessarily sequential in the collection: $array1['name1'] = 'blah'; $array1['name3'] = 'balh'; $array1['name2'] = 'balh'; etc.... Lets say we also have another collection that correlates: $array2['address3'] = 'blah'; $array2['address1'] = 'blah'; etc... Nested variable parsing within smarty would be a very useful feature: {section name='person' loop=$array1} Name: {$array1['name'.$person]} Address: {$array2['address'.$person]} {/section} Thats a simple example not based on real life at all. We are currently converting Bravenet over to a new Application Framework which uses smarty as its template engine so changing the data model isnt really an option. Heres a real life example of a loop we perform in our guestbook to display the entrys for the guestbook that I was not able to do directly within smarty. The $options array is the user defined question and the $entry array is the answer to the question. The user can define 13 questions (within $options). Both $options and $entry have other keys defined so a straight loop of the elements wouldnt work. Eventually I just broke the loops apart and duplicated the code 13 and hardcoded the key names. for ( $i=2; $i<16; $i++ ) { echo '<tr><td>'.$options["ql".$i].'</td><td>'.$entry["q".$i]).'</td></tr>'; } Not sure if its possible or reasonable to add such a thing to the smarty compiler (nested varaible pasring) but it would be useful to all smarty users. Bob Silva Senior Developer Bravenet.com

« previous php.smarty.dev (#211) next »