Categories > TinyButStrong general >

Can I change a variable value if an array variable have or not a value (empty val)?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Webys
Date: 2005-05-10
Time: 09:45

Can I change a variable value if an array variable have or not a value (empty val)?

Can I change a variable  value if an array variable  have or not a value (empty val) ?

Ex:
I need to change a bgcolor of the <td> html tabs if my array block value is empty .

if (age) empty bgcolor=red else bgcolorlet's say is white
<code>
<tr>
<td bgcolor=red></td>
<td bgcolor=red>[arr_blk.age]</td>
. . .
</tr>
</code>
and with TBS ?

<code>

<tr>
<td bgcolor=[var.color ifempty [arr_blk.age] var.color=white or change color ??? ]></td>
<td bgcolor=red>[arr_blk.age;block=td]</td>
. . .
</tr>
</code>

Any tips Skrol29, anyone?

Thanks.


By: RwD
Date: 2005-05-10
Time: 11:10

Re: Can I change a variable value if an array variable have or not a value (empty val)?

[arr_blk.age; if [val] == ''; then 'white'; else 'red']
By: RwD
Date: 2005-05-10
Time: 11:12

Re: Can I change a variable value if an array variable have or not a value (empty val)?

And as a sidenote I would like to add you should not use the bgcolor attribute at all and use double quotes around attribute values.

Also styling is a lot easier when you use css. Saves you a lot of trouble.

But these remarks falls outside the topic
By: Webys
Date: 2005-05-11
Time: 16:48

Re: Can I change a variable value if an array variable have or not a value (empty val)?

This is not ok
[arr_blk.age; if [val] == ''; then 'white'; else 'red']

I want to check an array variable "arr_blk.age" if its empty and if its empty the "var.color" wil take value red (if "arr_blk.age" has value will display the default value let's say white)

Can anyone do that with TBS...check an array value and if that's empty change other variable value with an value ?

Thanks.
By: Pirjo Posio
Date: 2005-05-11
Time: 22:51

Re: Can I change a variable value if an array variable have or not a value (empty val)?

What you are trying to do, can be done by the technique that Skrol29 has shown on Example-pages, Conditional Display. You just make two blocks with different bgcolors. One of the blocks is default. Check the example!
By: Webys
Date: 2005-05-12
Time: 18:38

Re: Can I change a variable value if an array variable have or not a value (empty val)?

I don;t want to have 2 blocks it make my template not clear because I'm doing a lot of cheks already...I wish to use one block and the color must change if "arr_blk.age" is empty the var.color to take other color tha default.

This should be added in the next version of TBS so the template code must be as minimal.

Don't you agree?

Thanks bust this is not a an elegant template solution ...to duplicate the template code for one check of array variable and change other var value.

Anyone has any ideea ho to do that,  Skrol29 ?
By: RwD
Date: 2005-05-13
Time: 11:55

Re: Can I change a variable value if an array variable have or not a value (empty val)?

I mixed red and white, but the code is working perfectly...

HTML
<table>
    <tr>
        <td bgcolor="[arr_blk.age; if [val] == ''; then 'white'; else 'red']">[arr_blk.age; block=tr]</td>
        <td bgcolor="[arr_blk.age; if [val] == ''; then 'white'; else 'red']">[arr_blk.name]</td>
    </tr>
</table>

PHP
$arr_blk[]     = array( 'age' => 10, 'name' => 'Eve' );
$arr_blk[]     = array( 'age' => 12, 'name' => 'Adam' );
$arr_blk[]     = array( 'age' => '', 'name' => 'God' );
$arr_blk[]     = array( 'age' => 24, 'name' => 'Snake' );

$tbs->MergeBlock( 'arr_blk', 'array', 'arr_blk' );
By: RwD
Date: 2005-05-13
Time: 11:56

Re: Can I change a variable value if an array variable have or not a value (empty val)?

euhm, so in the example I posted red and white are still on eachothers places. Just switch them...
By: Webys
Date: 2005-05-16
Time: 12:33

Re: Can I change a variable value if an array variable have or not a value (empty val)?

I wish NOT to duplicate the html, template code with TBS conditional blocks or other technique that is duplicate the code, block of html code ...to be a a clear template file.

I don't wish to take variable reference for color this one: arr_blk.age
I wish to check array value "arr_blk.age" if empty and, if empty change
JUST var.color value NOT arr_blk.age value

In big line is needed just to check if arr_blk.age empty if empty change  var.color = red

<td bgcolor=red>

else let default color = white

<td bgcolor=white>


Can TBS do that ???
By: Webys
Date: 2005-05-18
Time: 16:46

Re: Can I change a variable value if an array variable have or not a value (empty val)?

So TBS can't do that in latest version.

In future versions can I do that?

It's an important future that I need so I have to know as soon as posible.

Skrol29?

By: RwD
Date: 2005-05-19
Time: 12:35

Re: Can I change a variable value if an array variable have or not a value (empty val)?

What's the problem, It is not changing the value really, it is using the value to output the desired result. arr_blk.age can still be used as it is unchanged, tbs merely outputs 'white' or 'red'.

arr_blk.age IS NOT CHANGED by the method I show you.
and if you used propper CSS you wouldn't need to repeat the code all the time.

In fact you do not need to insert the bulky code if you use an onformat and simply add a "color" key into the arr_blk array for each row then. You could then use arr_blk.color instead! There are several ways to do what you want, I showed you one.
By: Skrol29
Date: 2005-05-19
Time: 14:44

Re: Can I change a variable value if an array variable have or not a value (empty val)?

Hi Webys,

If your problem is just to have an issue for your colour tuning, then solutions of Pirjo and Rwd are ok.

If you're looking for a way to change some Php variables depending to merged data, then TBS already gives such features. Parameters 'onformat' and 'onsection' enables you to call a user function when field is merged, or when a record is merged with MergeBlock(). Such custom functions enable you to do quite all you need in a the Php side. You can add and change columns of the current record, and of course you can change a global variable.

But in your case, I think changing a global variable won't be enough, because Var fields are supposed to be merged at the end of the template (despite they are merged immediatly when put in some parameters like 'if'). So it's better to define additional calculated columns to the current record, dedicated to your purpose.
By: Webys
Date: 2005-05-20
Time: 15:37

Re: Can I change a variable value if an array variable have or not a value (empty val)?

RwD - I allready made the what you propose:

" simply add a "color" key into the arr_blk array for each row then."

With onfprmat or onsection parameters was more code to add...so was no elegant solution

Thanks to all.
By: RwD
Date: 2005-05-20
Time: 16:16

Re: Can I change a variable value if an array variable have or not a value (empty val)?

Perhaps MySQL can solve your problem by adding a column to the output. I think this is the same as skrol29 is suggesting??