Re: referencing associative arrays using template variables
| From: | Jason Sweat | Date: | Thu, 28 Jun 2001 23:46:46 +0000 |
| Subject: | Re: referencing associative arrays using template variables | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-1082@lists.php.net to get a copy of this message | ||
Had a couple of more thoughts:
First, it was relatively trivial to reorder the array, you can to
$t->assign(array(
'DATA' => assos_to_idx($data, $xml),
'XML' => $xml));
using this function:
function assos_to_idx($assos, $keys)
{
$i = 0;
while( $i < count($assos)) {
$k = 0;
while ( $k < count($keys)) {
$out[$i][$k] = $assos[$i][$keys[$k]];
$k++;
}
$i++;
}
return $out;
}
Second thought:
With a relatively simple change I could implement recursive template in my
script. What I would need is a Smarty::displays and ::fetchs function that
take a first argument that is a string containing the template rather than
the name of the template. (This would also be useful for retrieving
templates from a database, run the query to retrieve the template and used
the result in a $temp->displays($result_from_db...))
I could then have a template with a section that runs over the keys array
and generates the final template that I use with the $DATA array to publish
the final xml document.
Jason
-----------------
> My inital instinct was to try to write something like
> {$DATA[data].{$XML[xml]}}
> with the inner smarty brackets indicating a template variable that should
be
> evaluated before being applied as the assosiative key.
Yep, that would be peachy, except that is not quite possible since it
requires recursive template evaluation. I'll try to keep it in the back
of my mind in case a bright idea decides to emerge out of there one day.
-Andrei
* There is no knowledge that is not power. *