|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Budda Smarty Regular
Joined: 19 Apr 2003 Posts: 53 Location: Lymm, Cheshire. UK
|
Posted: Tue Sep 09, 2003 12:47 pm Post subject: Array indexes and how to use them in Smarty |
|
|
After doing a search of the forums i can't find any discussion that can help me with my problem.
I have two arrays of strings which are available in my Smarty template.
In the Smarty debug they are listed:
Code: |
sexText => Array (2)
0 => Woman
1 => Man
yesNoText => Array (2)
0 => No
1 => Yes
|
I then have a number of other Smarty variables which are either =1 or =0.
I would like to dipslay a string held in the arrays above based on the numeric value of the other variables (they will act as the array index number).
so if $sex=0, i would like to do $sexText[$sex] and get "Woman" output in my Smarty template.
However, I can't suss out how it works in Smarty?! Any suggestions people?? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Sep 09, 2003 6:39 pm Post subject: |
|
|
hmmm. Works for me. What version of Smarty are you using? I tried with the current CVS.
Note, {$sexTest.$sex} also works. |
|
Back to top |
|
Budda Smarty Regular
Joined: 19 Apr 2003 Posts: 53 Location: Lymm, Cheshire. UK
|
Posted: Wed Sep 10, 2003 9:22 am Post subject: |
|
|
I'm using the last stable public version, 2.5
I failed to mention one thing which might make a difference thinking about it now. All my variables are part of an object i assign to a smarty variable.
So i need to use {$result->sex} to get the index number 0 or 1
and then i need to use $result->sexText to access the array with the two elements in, indexed as 0 and 1.
{$result->sexText.$result->sex} causes the error:
Code: | Warning: Illegal offset type in C:\www\pma\htdocs\Var\Cache\Templates_c\%%149\%%1495695858\cardiovascularRiskResults.tpl.php on line 26 |
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|