Categories > TinyButStrong general >

Does 'when' only support automatic fields?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: allenylzhou
Date: 2013-11-03
Time: 01:41

Does 'when' only support automatic fields?

<?php
    $blah= array('mode' => 1);

    $TBS = new clsTinyButStrong;
    $TBS->LoadTemplate('blah.htm');
    $TBS->MergeField('blah', $blah);
    $TBS->Show();
?>

<td><strong>Blah[onload;block=td;when [blah.mode]==1]</strong></td>

The conditional block doesn't work, but if I change blah.mode to var.blah.mode then it works.
Is this expected behaviour? Can someone offer an explanation?
By: Sarah Kemp
Date: 2013-11-04
Time: 18:19

Re: Does 'when' only support automatic fields?

Essentially, the difference you are seeing between blah.mode and var.blah.mode is that var.blah.mode will be processed onload (http://www.tinybutstrong.com/manual.php#html_field_auto) because in a when block the special field [var] is processed with its parent (the onload).

[blah.mode] (without var), on the other hand, is processed when your MergeField is called, which is after the onload has already run. This means that [blah.mode] would not be replaced with its value (1) in time to be evaluated against the hardcoded '1' which is checked onload. Onload runs as soon as you LoadTemplate().

I hope that helps.