TinyButStrong - the PHP Template Engine
Categories > [old] TbsOoo & TinyDoc >

MergeBlocks and assoc array

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

By: jef
Date: 2012-02-10
Time: 16:42

MergeBlocks and assoc array

i've got an assoc array with al my data in it, eg
nd is now Array(
      [haddr] -> Array(
             [post] ->Array (
                       [bedrijf] -> 'Company',
                       [address] -> 'Address',
              )
       )
      [caddr] -> Array (
            [post] -> Array (
                     [bedrijf] -> '2nd Company',
                     [address] -> 2nd address',
            )
      )
)

If i use MergeField, is can just use a ref like this in the template
MergeField ('nd', $nd) and the fields [nd.haddr.bedrijf] and [nd.caddr.address] will be properly filled in.
If i want to use a MergeBlock, i have to do it like this
MergeBlock('nd.haddr.post', array($nd[haddr][post])) which is a lot more cumbersome. I need this mergeBlock, to delete when an array field is empty, otherwise i could have used MergeField.

jef
By: Skrol29
Date: 2012-02-11
Time: 01:02

Re: MergeBlocks and assoc array

Hi Jef,

What is your question?

> I need this mergeBlock, to delete when an array field is empty, otherwise i could have used MergeField.

You can use MergeField and catch if the data is empty using parameter "noerr" and "magnet" together on the first field. (see manul for parameter "magnet")

> If i want to use a MergeBlock, i have to do it like this ... which is a lot more cumbersome.

Is this available for you ? :
PHP:
$TBS->MergeBlock('nd', $nd);
OpenOffice:
[nd.post.bedrijf;block=...][nd.post.address]