By: SunWuKung
Date: 2009-02-18
Time: 10:21
|
define new variables in the template
Hi,
I would like to use gender specific strings in my template. I can do it with the current setup, but they are uncomfortably long compared to how frequent they are.
[usr.ref_gender;if [val]='male';then 'his'; else 'her']
|
Is there a way to define variables in the template and use them later?
Something like
[var.hisher]=[usr.ref_gender;if [val]='male';then 'his'; else 'her']
I like [var.hisher] style.
|
I know that this could be done way easier on the server side, but for me the whole point is to let my users do this.
Thanks for the help.
SWK
|
By: Skrol29
Date: 2009-02-18
Time: 17:07
|
Re: define new variables in the template
Hi SunWuKung,
It is not possible currently. You're supposed to prepare data before to merge them.
|
By: James
Date: 2009-03-06
Time: 17:01
|
Re: define new variables in the template
Where are you pulling your data from? If the field 'ref_gender' is coming from a database (as in, the person is logged in and you have their gender stored in their account info.) you can just set the variable in the PHP file that calls the template. Then you can do what you're trying to do. Ex:
In your PHP file
$query ='SELECT gender FROM users WHERE user_id = "'.$id.'"';
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$gender = ($row['gender'] = 'male')? 'his' : 'her';
TBS->MergeBlock('result',$cnx_id,$query);
Now in the template you can use [var.gender] and it will be replaced by "his" or "her". If you're not familiar with the PHP part, the ? means if the condition (that gender = male) evaluates to true, then use the first value, in this case 'his' -- if it doesn't, then use the value after the : , in this case 'her'
Granted it does require two queries to the database, but since you're only fetching a single row you shouldn't notice any effect on performance.
|
By: SunWuKung
Date: 2009-03-06
Time: 22:17
|
Re: define new variables in the template
Hi James,
thanks for your answer, you are absolutely right. As I said I know that this could be done easier on the server side.
My situation is that I expose the templates to my users. They can modify it and include the data that is made available to the template.
So far so good. But the language of the template could be english, greek or I don't know what. Plus I can easily imagine other variable dependent language elements like plural in English.
I just don't want to deal with these. I want to simply expose the data for the variables - like gender - and let the template writer worry about how that data will effect the result in his/her particular template in the given language.
TBS does this right but using the whole conditional statement every time makes the template look awful because it is so frequent. It would be much nicer if the result of a tbs field could be assigned to a variable accessable to TBS.
I currently see no solution to this but to live with it.
Thx.
SWK
|
|
Posting in progress.
Please wait...
|