Re: [SMARTY] Re: Assembling variables in the template
| From: | Dmitri Zakharov | Date: | Wed, 19 Feb 2003 20:04:19 +0000 |
| Subject: | Re: [SMARTY] Re: Assembling variables in the template | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-7922@lists.php.net to get a copy of this message | ||
Hi SavaJr,
Can you give an example, please?
I tried the following. Doesn't work for me.
Is this syntax correct?
If I walk directly through $test_results associative
array I don't have any problems getting it's values.
But here I am trying to retrieve innermost
values of $test_results array using other template
variables as keys, and that doesn't seem to work.
{section name=sess loop=$sessions_sorted}
{section name=rsf loop=$res_showfields}
{assign var="sessresults" value=$test_results.$sessions_sorted[sess]} {assign var="resrow" value=$sessresults.$key}
{assign var="fieldval" value=$resrow.$res_showfields[rsf]}
<td>{$fieldval}</td>
{/section}
{/section}
- dmitri
Savajr wrote:
Hello Dmitry Almost ANY data structure can be split into subvalues (i.e. assign's) For {$test_results.$sessions_sorted[sess].$key.$res_showfields[rsf]} You'll have 3-4 assigns. Not too good, but is a solution. --------------- Ruslan Savchyshyn http://www.MagneticOne.com/ Web development and design services -----Original Message----- From: Dmitri Zakharov [mailto:zakd@max-t.com] Sent: Wednesday, February 19, 2003 8:16 PM To: smarty-general@lists.php.net; Dmitri Zakharov Cc: smarty-general@lists.php.net Subject: [SMARTY] Re: Assembling variables in the template OK, for anybody who's interested, I found solution for the first problem {* POINT 1 *}: Instead of {assign} I used {capture} as follows: {capture name=key}{$client_groups[cg]}-{$reqsizes[rs]}-{$targets[tg]}-{$runs[rn]" }{/capture} Now I have expected $key variable in the template. The second one ({* POINT 2 *}) is still giving me some troubles. HEEEEELLLLLLP!!! Dmitri Zakharov wrote:Hi all, I have quite a bit of {section} statements in my template. Everything goes smoothly untill: (@see template snippet at the end of this message) {* POINT 1 *}. Here I am trying to generate $key variable. Looks like value attrubute of the assign custom function can be a string, not something composed of other template variables. What I get here is '---' as opposed to what I expect ex.: '1-4-2-3'. Is there any other way to do that? {* POINT 2 *} Here I am trying to retrieve values from the $test_results array, which has the following structure: $test_results = array( 'sess_23' => array( '1-4-2-1' => array( // this is a key from POINT 1'avg_rate' => 999.99, 'elapsed_time' => 999, 'cpu_load' => 99,), '1-4-2-2' => array('avg_rate' => 888.88, 'elapsed_time' => 888, 'cpu_load' => 88,), ... ), 'sess_48' => array( ... ), ... ); Again Smarty doesn't like: {$test_results.$sessions_sorted[sess].$key.$res_showfields[rsf]} Is there any work around? Or maybe I am doing somethin wrong? Any helpis appreciated! ;o) - dmitri {* Test results rows *} {section name=cg loop=$client_groups} {section name=rs loop=$reqsizes} {section name=tg loop=$targets}{section name=rn loop=$runs} <tr bgcolor="{#commonRowsColor#}"> <td>{$client_groups[cg]}</td> <td>{math equation="r * t" r=$reqsizes[rs] t=$targets[tg]}</td> <td>{$targets[tg]}</td> <td>{$runs[rn]}</td>{* POINT 1 *} {assign var=key value= "$client_groups[cg]-$reqsizes[rs]-$targets[tg]-$runs[rn]"}{* show selected result fields for each session *} {section name=sess loop=$sessions_sorted} {section name=rsf loop=$res_showfields} <td> {* POINT 2 *} {$test_results.$sessions_sorted[sess].$key.$res_showfields[rsf]}</td> {/section} {/section} {* end of show selected result fields for each session *}</tr> {/section}{/section} {/section} {/section} {* End test results rows *}