Replies: 8   Views: 3305
Addtemplatevariable table issue
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 lobbygov  · 20-01-2011 - 00:00

Has anyone else experienced trouble with using the addTemplateVariable function to replace variables in a table?

I've tried my own template and the template included with PHPDOCX Pro, but in both cases the script not only replaces the variables, but it creates several rows of the variables after my content is added. Additionally, it creates several copies of my header row in the table, even though no variables are included.

I wonder if it's a bug?

Posted by admin  · 11-04-2013 - 12:12


We're working on it. You'll have an answer today.


Posted by admin  · 11-04-2013 - 12:12


The example available in phpdocx pro package is correct, but the one included in Documentation was outdated. Now it's fixed.


Posted by zstov  · 11-04-2013 - 12:12

I have also problem with that.
When I put in the table header a,b,c,d ... for each column, I get the following result:

a b c d
a b c d
a b c d
a b c d
Product A 10 5 5
Product B 20 30 5
Product C 25 7 5

When I change it to A1,B1,C1,D1 it is okay


Posted by clombard  · 11-04-2013 - 12:12

Nobody have an answer for this question ?

I've got the same error with too much severals rows.

Posted by profeo  · 11-04-2013 - 12:12

I have problem with adding item to table template after making changes in file.

When I have default table from template like:
[code] Weight (Kg) Price (€)
from the example everything is OK, but when only I'm trying to change var $NAME$ to for example $STARTDATE$ the table is filled with only one row, and the rest values from array are skipped.

Do you have any idea about this problem / any solution?

Posted by bgauthier  · 11-04-2013 - 12:12

I have the same problem, any help would be appreciated

Thank you

Posted by DamienB  · 11-04-2013 - 12:12

I have the same problem as profeo with populating a table in a template.

Let's say i have a simple table in my template with the two columns, two rows. The first row is just a header. The second contains the variables $ethnicity$, $total$. The array I pass to $docx->addTemplateVariable is:

[0] => Array
[ethnicity] => White
[total] => 440

[1] => Array
[ethnicity] => African American
[total] => 158

[2] => Array
[ethnicity] => Hispanic
[total] => 176

[3] => Array
[ethnicity] => Asian / Pacific Islander
[total] => 14

[4] => Array
[ethnicity] => American Indian
[total] => 4

[5] => Array
[ethnicity] => Other
[total] => 117



According to your documentation/ tutorials, I should expect the table in my template to be populated with 6 rows of data. Instead, I only get one row. What do I need to do to troubleshoot this?