Categories > TinyButStrong general >

Array referencing

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Rune
Date: 2013-01-14
Time: 15:40

Array referencing

Is there any way to do a direct array reference, like...

$test = array("a", "b", "c");
$TBS = new clsTinyButStrong;
$TBS->LoadTemplate('test.html');
$TBS->MergeBlock('test', 'array', $test);
$TBS->Show();

And then in the template, reference by array index, like...

[test.0]
[test[0]]

To read the first item, etc...
By: Sarah
Date: 2013-01-14
Time: 17:09

Re: Array referencing

Your first code block looks right, but in the second one, you would need to define the block boundaries, I think. For example, if you wanted to print each element of $test in a <p> you would do:

<p>[test;block=p]</p>

And TBS would automatically create a <p> element for each item in your array, giving you:

<p>a</p>
<p>b</p>
<p>c</p>

For clarity's sake (at least), it is probably best to call your block something different than your array, e.g. 'block1'. In this case your merge would look like $TBS->MergeBlock('block1','array',$test) and your tag would look like [block1;block=p]

There are other ways to define blocks if this simple way doesn't work for you, but you need your block boundaries defined to use MergeBlock. More info here: http://www.tinybutstrong.com/manual.php#html_block
By: Rune
Date: 2013-01-15
Time: 10:25

Re: Array referencing

Yeh, I think I figured out where I went wrong. I am not trying to render the elements automatically, but individually reference an element by index. For example rendering only item 2 (b). Seems like its working if I assign the array with

$TBS->MergeField('test', $test);

and reference with

[test.1]