Forum


Replies: 3   Views: 3734
Several table variables inside docx template: only first table will be filled.
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by vchaikevitch  · 25-10-2015 - 23:45

Hallo,

the version I currently use is 3.7. If I use a table variables in a DOCX template file like

==========================================
Name              | Test1        |     Test2        |     Test3        |
==========================================
$V1_Name$    | $V1_1$    |     $V1_1$    |     $V1_2$    |
==========================================

It works fine. But adding the same table twice to the template file like

==========================================
Name              | Test1        |     Test2        |     Test3        |
==========================================
$V1_Name$    | $V1_1$    |     $V1_1$    |     $V1_2$    |
==========================================

asdjlfkjasdlkfjasdjflkasdjflk

==========================================
Name              | Test1        |     Test2        |     Test3        |
==========================================
$V1_Name$    | $V1_1$    |     $V1_1$    |     $V1_2$    |
==========================================

causes problems. In the result DOCX document the first table is filled nearly correct: all data will be added correct but an additional row will be added containing only the first column with not replaced variable $V1_Name$. For the second table no row will be filled correct: the first column in each row contains $V1_Name$, other colums are empty.

Thanks a lot for hins and possible solutions.

Best regards,

Vitali

Posted by admin  · 26-10-2015 - 08:38

Hello,

Using the old phpdocx 3 we recommend you use unique placeholders for each table or you'll get unexpected results.

Regards.

Posted by vchaikevitch  · 26-10-2015 - 13:05

Hallo,

I would say it's look like a bug... It works fine for simple variables and not for table variables and it is actually a legitimate requirment to use the same variable several times in one template and not to be forced to add fake variables and fill them extra. It would be great to fix the issue.

Best regards,

Vitali

Posted by admin  · 26-10-2015 - 14:41

Hello,

Phpdocx 4 added new options and a lot of improvements. For example the option firstMatch in the replaceTableVariable method:

http://www.phpdocx.com/api-documentation/templates/replace-table-variable-Word-document

But using phpdocx 3 we recommend you to don't duplicate the placeholders when working with tables or lists.

Regards.