Search code examples
phpms-wordopentbstinybutstrong

How to create a specific openTBS Word Template?


I have a php program that uses TinyButStrong together with the OpenTBS Plugin. I tried many examples and edited the xml directly too. nevertheless I don't get it and all the experimenting starts to frustrate me, so here is my problem:

The template is just a standard letter to customers with address information on top like this:

[a;block=w:body]

[a.company_name; magnet=w:p]
[a.first_name][a.last_name]
[a.street]  
[a.postalcode] [a.city]
[a.country]  

As xml it looks like:

<w:p w:rsidR="001A4536" w:rsidRDefault="007D3CAF">
    <w:r w:rsidRPr="007D3CAF">
        <w:t>[a;block=w:body]</w:t>
    </w:r>
</w:p>
<w:p w:rsidR="007D3CAF" w:rsidRDefault="007D3CAF">
    <w:r w:rsidRPr="007D3CAF">
        <w:t xml:space="preserve">[a.company_name; magnet=w:p] </w:t>
    </w:r>
</w:p>
<w:p w:rsidR="007D3CAF" w:rsidRDefault="007D3CAF">
    <w:r w:rsidRPr="007D3CAF">
        <w:t>[a.first_name] [a.last_name]</w:t>
    </w:r>
</w:p>
<w:p w:rsidR="007D3CAF" w:rsidRDefault="007D3CAF" w:rsidP="007D3CAF">
    <w:r>
        <w:t>[a.street]</w:t>
    </w:r>
</w:p>
<w:p w:rsidR="007D3CAF" w:rsidRDefault="007D3CAF" w:rsidP="007D3CAF">
    <w:r>
        <w:t>[a.postalcode] [a.city]</w:t>
    </w:r>
</w:p>

In case there is no company name or no first and lastname there shouldn't be a line wasted. How do I achieve that?

If there would be a better way to create word docs than with openTBS I would consider that too?


Solution

  • The first thing is that your block definition block=w:body is not appropriate because there can be only one <w:body> element in the XML content. But TBS will duplicate this element as for each record in your data.

    You should change block=w:body with block=tbs:p+tbs:p+tbs:p+tbs:p+tbs:p which defines the block over 5 paragraphs.

    In case there is no company name or no first and lastname there shouldn't be a line wasted. How do I achieve that?

    The TBS field [a.company_name; magnet=w:p] is correctly used. You can us the same for firstname+lastname but in this case you have to define a data column which is the concatenation of the both in order to use the magnet parameter on it. If you cannot define a data column, you can use parameter ondata with a custom PHP function in order to add a virtual column.