Categories > TinyButStrong general >

more MergeBlock fun

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: starmonkey
Date: 2005-11-23
Time: 06:34

more MergeBlock fun

hi there - another simple problem I think!

in my .php, I have

$blog_post = site_get_blog_post_by_id($_GET['id']);
echo '<pre>'; print_r($blog_post); echo '</pre>';
$TBS->MergeBlock('thepost','array','blog_post');

the echo statement shows me a filled array of data that i want, for example:

Array
(
...
[title] => lipsum test post longer
...
)

however, in my.html, I use the following:

view a post
[thepost.title]

and I see:

TinyButStrong Error (Array value): Can't merge [thepost.title] because sub-item 'title' is not an existing key in the array. This message can be cancelled using parameter 'noerr'.

I dont' undersstand, it should be there?

thanks,
sm
By: Solaris
Date: 2005-11-23
Time: 13:55

Re: more MergeBlock fun

i think this is wrong
$TBS->MergeBlock('thepost','array','blog_post');
and it should be
$TBS->MergeBlock('thepost','array',$blog_post);

see
http://lamp.clausvb.de/tbs_examples/loop_block.php
http://www.tinybutstrong.com/examples.php
for further informations.

CU
Solaris
By: Skrol29
Date: 2005-11-23
Time: 17:20

Re: more MergeBlock fun

Hi Solaris,
Both of your syntaxes are ok.

I think SmartMonkey has a problem because its variable $blog_post is not an array of records (I mean an array of array), but a single record (I mean a simple array).

Its code should be:
$blog_post = array();
$blog_post[] = site_get_blog_post_by_id($_GET['id'])
$TBS->MergeBlock('thepost','array','blog_post');

or:
$TBS->MergeBlock('thepost','array',array($blog_post));
By: starmonkey
Date: 2005-11-24
Time: 00:29

Re: more MergeBlock fun

hi there and thanks for the replies. according to the manual, what I'm doing is correct:

Array
The argument Source has to be a PHP Array or the keyword 'array'. If you use the keyword 'array', then the argument Query has to be a Php Array or a string that represents an array contained or nested in a global variable.

String syntax: 'globvar[item1][item2]...'
'globvar' is the name of a global variable $globvar which must be an array.
'item1' and 'item2' are the keys of an item or a subitem of $globvar.
Example:
$TBS->MergeBlock('block1','array','days[mon]');
This will merge 'block1' with the value $day['mon'] assuming it is an array.
It is possible to represent variable's name without items.
Example:
$TBS->MergeBlock('block1','array','days');

There are two advantages in using a string to represent the array:
-> Items will be read directly in the Array (assigned by reference) instead of reading a copy of the items. This can improve the performance.
-> You can use dynamic queries.

Displaying the key of current record:
You can use the virtual column '$' which will display the key of the current record. This can be useful especially for dynamic queries and sub-blocks.
Example: [block1.$]

Structure of supported arrays:
Items of the specified Array can be of two kinds: simple values with associated keys (case 1), or array values for whom items are themselves simple values with associated keys (case 2).

Case 1:
Example:     ['key1']=>value1
['key2']=>value2
...
The returned Record Set consists of a column 'key' containing the name of the key, and a column 'val' containing the value of the key.

Case 2:
Example:     [0] => (['column1']=>value1-0 ; ['column2']=>value2-0 ; ...)
[1] => (['column1']=>value1-1 ; ['column2']=>value2-1 ; ...)
[2] => (['column1']=>value1-2 ; ['column2']=>value2-2 ; ...)
...
The returned Record Set consists of the columns 'column1', 'column2',... with their associated values.

so I'm going for case1, and trying to link the associative array by reference to the block rather than copying the array by supplying the assoc array directly into the MergeBlock.

According to the above manual entry, I don't think I _should_ need to do:

$TBS->MergeBlock('thepost','array',array($blog_post));

but I'll give it a try and see if that works but really, I should be able to do what I'm doing? perhaps the variable is going out of scope or something.

thanks heaps for your replies!

p.s. it's "Star" monkey, not "Smart" monkey, but thanks for the compliment :) hehe
By: Solaris
Date: 2005-11-24
Time: 09:17

Re: more MergeBlock fun

yeah skrol is right ... your array is wrong

Array
(
...
[title] => lipsum test post longer
...
)

cannot work it has to be:

Array
   (
       [0] => Array
           (
               [u_id] => 1
               [u_name] => Claus
               [title] => Your StarMonkey Title
           )
       [1] => Array
           (
               [u_id] => 2
               [u_name] => Kelvin
               [title] => Your StarMonkey Title
           )

please look at the examples. IMHO you did not do that, otherwise you would have seen the difference.

your array would work with
<div>[thepost.key;block=div] - [thepost.val]</div>
i think.

CU
Solaris