Forum


Replies: 2   Views: 259
Recursively replace a variable in a template that is loaded from an external file
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 mybuh  · 25-02-2025 - 06:50

I load a template and replace a variable from an external file in it. The external file also contains this variable, but I can't replace it again.
Code example:
$docx = new \CreateDocxFromTemplate('nds.docx');
$docx->setTemplateSymbol('[', ']');
$docx->replaceVariableByExternalFile(['nds_cert' => 'nds2.docx'], ['matchSource' => true]);
$docx->replaceVariableByText(['nds_cert' => 'bbb '], ["firstMatch" => false]);
$docx->CreateDocx('nds3.docx');
File contents.
nds.docx:
[nds_cert]


nds2.docx:
Aaaa
[nds_cert]

I get the output
nds3.docx:
Aaaa
[nds_cert]

How to get in the file nds3.docx
Aaaa
bbb

?