TinyButStrong - the PHP Template Engine
Categories > TinyButStrong general >

mergefield and mergeblock in same template?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs

By: Paul
Date: 2014-04-13
Time: 01:53

mergefield and mergeblock in same template?

Hi all,

Is there any way I can use MergeField and MergeBlock in the same template?

I find that whichever one I call first, messes up the 2nd one, ie: does not interpret.

So.....

$TBS->MergeBlock($title, $dataset);
$TBS->MergeField($title, $dataset);

will merge the block correctly, but not the field


and


$TBS->MergeField($title, $dataset);
$TBS->MergeBlock($title, $dataset);


will merge the field correctly, but not the block


By: Skrol29
Date: 2014-04-13
Time: 03:20

Re: mergefield and mergeblock in same template?

You can use MergeField() and MergeBlock() as many times you wish. But each name (block or fields) can be merged only once. The is because MergeField() and MergeBlock() do merge all the TBS fields of the corresponding name.
By: Paul
Date: 2014-04-13
Time: 15:37

Re: mergefield and mergeblock in same template?

Thank you for your quick reply, it is appreciated.

I can work around this.

paul
By: Paul
Date: 2014-04-14
Time: 01:14

Re: mergefield and mergeblock in same template?

Hi, skrol29 have you perhaps some advice for me regarding my post?

I have made a generic reportwriter using tbs, so how would I be able to determine if I have to run a MergeField()  on the template or a MergeBlock()?

Would using tags work?

eg: pseudo code.... if locate('<my_tag>') then MergeBlock() else MergeField();

If this works, I could make sure the template adheres to the <tag> syntax method.

I cant search for the "block" keyword, as there could be multiple blocks on different datasets in the same template.

thanks for your help
paul

By: Skrol29
Date: 2014-04-16
Time: 01:52

Re: mergefield and mergeblock in same template?

Hi,

MergeBlock() works even if the definition in the template does not use parameter "block".
In this case, MergeBlock() will merge all fields with the first record of the data.

So in a kind of way, MergeBlock() can do both MergeBlock() and MergeField().

The problem is: what to do if you have defined several block with the same name, or one block and other free fields with the same name.
In this case, you cannot chose a good solution: MergeField() won't merge any block, and MergeBlock() will process all blocks as if they where a single one, and free fields will be merged with the first or last record depending of they place relatively to the block.