0

I use openTBS to parse an invoice template. The invoice address is supplied via a custom function. I would like to conditionally more information to the filled in data.

I was thinking of permitting the invoice address (the filled in data) to contain another TBS field, e.g. for a person to speak to, and have TBS re-parse the form. In other words, can I make TBS parse a template twice if the first run supplies a new TBS field?

Example:

[abk.invoiceaddress]

--- is replaced with -->

ACME inc.
[abk.person]
Somestreet 123
Somecity 54321

--- should be replaced with -->

ACME inc.
Mr. Knowitall
Somestreet 123
Somecity 54321

There seems to be no option for recursive replacement and calling MergeField() twice does not have the desired effect.

patmin
  • 117
  • 1
  • 10

1 Answers1

1

By default, TBS prevents from TBS fields injection when merging data. Otherwise it could be a security issue.

By default, if the data is:

ACME inc. [abk.person] Somestreet 123 Somecity 54321

then it will be merged as:

ACME inc. &#91abk.person] Somestreet 123 Somecity 54321

The string &#91 is the unicode for [, so this is not visible for lot of templates.

But you can lift this protection using parameter protect=no

See https://www.tinybutstrong.com/manual.php#html_field_prm_protect

Skrol29
  • 5,402
  • 1
  • 20
  • 25
  • Thanks very much, Skrol. I tried this with ```[abk.invoiceaddress;protect=no]```. To be sure, I also set ```$TBS->setOption('protect', false);``` in my script. Still, I cannot get recursive merging to work. Drilling into the generated DOCX file I see the plain '[' character in document.xml. Can it have to do with openTBS or the fact that I use MergeField() with my own callback function? – patmin May 06 '21 at 08:28
  • you have to merge 'abk' ( MergeFields() or MergeBlock() ) twice, once for the fields in the template, once more for those appeared by the data – Skrol29 May 07 '21 at 13:30