Categories > Your tips & tricks >

Speed up block processing with onload instead of onshow

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Sarah
Date: 2013-02-14
Time: 00:31

Speed up block processing with onload instead of onshow

This may be obvious to anyone reading, but it is easy to forget. If you are using blocks and subblocks in your template, it may be considerably longer by the time TBS gets to the onshow event. If you have a block like this:

<table>
  <tr>
    <td>[myBlock.fieldName;block=table;]</td>
    <td>[onshow.totalFields;]</td>
  </tr>
</table>

Where myBlock is a semi-large array or object (meaning you will have several tables at the end) - you can save a lot of processing by simply changing onshow to onload. If you choose an earlier event, you can merge the tag once, when the template loads, instead of once for every item in myBlock.

I think it would be safe to say whenever possible, you should use the earliest event you can. With that in mind, I am trying to determine the order of tag processing. I believe it goes like this:

//assuming:
$TBS->LoadTemplate("path/to/template");
$TBS->MergeBlock('blockName', $arrayOrObject);
$TBS->Show();

1. onload
2. ondata
3. blockName
4. onshow

Though [var] and [val] fields don't fit into this ordering, I will try to explain them. [var] and [val] fields are a little different as they will merge based on the tag they are used with.

[var] fields will merge at the same time as whatever they are included with and have no understanding of the field you are currently merging (you could not use var.field to access blockName.field - use val for that), e.g. the var in this example will merge when blockName merges:

$myGlobal = 'go';
...
<p>
[blockName.field;block=p;when [var.myGlobal]='go']
</p>

[val] fields are equal to the current data item. For example, you would use:

//good
[blockName.field;when [val]='OK']

Instead of:

//bad
[blockName.field;when [blockName.field]='OK']

I hope anyone reading will feel free to correct, clarify, or expand on my explanation of this.