Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Array indexes and how to use them in Smarty

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Budda
Smarty Regular


Joined: 19 Apr 2003
Posts: 53
Location: Lymm, Cheshire. UK

PostPosted: Tue Sep 09, 2003 12:47 pm    Post subject: Array indexes and how to use them in Smarty Reply with quote

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?! Sad Any suggestions people??
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Tue Sep 09, 2003 6:39 pm    Post subject: Reply with quote

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
View user's profile Send private message
Budda
Smarty Regular


Joined: 19 Apr 2003
Posts: 53
Location: Lymm, Cheshire. UK

PostPosted: Wed Sep 10, 2003 9:22 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP