For Programmers: Free Programming Magazines  


Home > Archive > PHP Smarty Templates > July 2004 > dumb q (variable assignment from assoc arrays)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author dumb q (variable assignment from assoc arrays)
Christopher J. Mackie

2004-07-08, 4:04 pm

I've got a template where the following works perfectly

$fieldlist=array ( 'LName' => 'Mackie', 'FName' => 'Christopher', 'PrefName'
=> 'CJ');

$smarty->assign( 'field_list', $fieldlist );

----- in fieldlist.tpl
{foreach from=$field_list item=v key=k}
<tr>
<td>{$k}: </t>
<td>{$v}</t>
</tr>
{/foreach}

--------- output ---------
LName: Mackie
FName: Christopher
Prefname: CJ
--------------------------

Reading the manual ("assigning vars from associative arrays"), it seems to
me that this should also work

{$field_list.PrefName}
{$field_list.FName}
{$field_list.LName}

------- to produce
CJ
Christopher
Mackie

But I can't get that second syntax to work at all--not using 'dot' syntax,
not using [0] syntax, and certainly not using object syntax. The object
syntax is the only one that actually throws an error; the others just return
nothing.

The manuals make it look easy: my templates make it seem impossible. Can
anyone tell me what I'm missing? I'm sure it's something incredibly
dumb--but I've read that man page 50x, and I can't see it.

Tx, --CJ
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com