#2804·PHPWord

Unable to insert multiple tables into a Word template using the same placeholder name

Author: kishan-pinetcoCreated Jul 26, 2025Updated Apr 29, 2026
LabelsBug Report

Describe the bug and add attachments

Hello PHPWord team,

I'm facing an issue when trying to insert multiple tables using the same placeholder name with setComplexBlock() in a Word template. While regular text placeholders (e.g., ${name}) can be used multiple times in the template and replaced correctly, this does not seem to be the case for table placeholders using setComplexBlock().

Actual Behavior Only the first occurrence of the placeholder gets replaced with the table. Any subsequent instances of the same placeholder name are not replaced.

The same ${table} placeholder exists multiple times in the .docx template file. Only the first one is replaced correctly.

Image

Please let me know if there's a workaround for this or not.

Thank you for your great work on this library!

Expected behavior

When using the same placeholder (e.g., ${table}) multiple times in a template, each instance should be replaced with the respective table block generated in PHP, similar to how text placeholders work.

Steps to reproduce

$tableStyle = [ 'width' => 100 * 50, 'unit' => 'pct', 'cellMargin' => 150, 'borderColor' => '000000', 'borderSize' => 6, ];

$table = new Table($tableStyle); $table->addRow(); $nameCell = $table->addCell(2000); $nameCell->getStyle()->setGridSpan(); $nameCell->addText('Name', ['bold' => true, 'size' => 8]); $processor->setComplexBlock('table', $table);

PHPWord version(s) where the bug happened

1.2

PHP version(s) where the bug happened

8.2

Priority

  • I want to crowdfund the bug fix (with @algora-io) and fund a community developer.
  • I want to pay the bug fix and fund a maintainer for that. (Contact @Progi1984)