[FX.php List] FX and Smarty dealing with arrays

Michael Layne fx at 9degrees.com
Tue Dec 20 21:42:37 MST 2005


I know some of you are Smarty Template fans, so here's a question  
(and a bit of background).  First, I've tried to be thorough, so  
forgive the length of the post:

I finally took the leap and tried to implement Smarty on a new and  
somewhat sizable project.  It was a bit of a curve for a couple of  
days, but I do like the further separation of presentation and logic.  
(I've been rolling my own for some time) And yes, I've scoured the  
Smarty documentation, but only examples are dealing with MySQL/ 
PostgreSQL.  That would be fine, but this solution is all FM7SA back- 
end.  I'm sure the root of my problem is my understanding (or lack  
thereof) of associative arrays as dished out by FM7SA's XML.

The challenge is creating a dynamic dropdown with FM data within  
a .tpl file.

First the normal PHP way: (I can do this all day long)

             <select name="accountCode">
             <option selected="selected">select...</option>
             foreach ($result['data'] as $option) {
                 echo "<option value=\"" . $option['account_codeID'] 
[0] . "\">" . $option['account_code'][0] . "</option>\n";

My first successful Smarty template:

data is an associative array of states:
$states = array (
     'AL' => 'Alabama',
     'AK' => 'Alaska',
     'AZ' => 'Arizona',

.php code:
.tpl code:
                   {html_options name=st options=$abbr selected=$st}

so... I cannot figure out how to get the above PHP/FX result in an  
array or format that will work with the Smarty template.  the closest  
I got was something like:

             <option "value="101">101</option>
             <option value="sample1"> sample1 </option>
             <option "value="102">102</option>
             <option value="sample2"> sample2 </option>

of course I'm looking for:

             <option value="101"> sample1 </option>
             <option value="102"> sample2 </option>

That's it.  Thanks very much in advance to anyone who can point me in  
the right direction.


Michael Layne  :  9 degrees development  :  www.9degrees.com  :   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.iviking.org/pipermail/fx.php_list/attachments/20051220/943e0ba8/attachment-0001.html

More information about the FX.php_List mailing list