Forum


Replies: 6   Views: 275
Replacing multiple images
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 admin  · 25-04-2024 - 11:20

Hello,

You can add as many contents as needed in the WordFragment, including new placeholders to be replaced. For example:

$contentFragmentA = new WordFragment($docx, 'document');
$contentFragmentA->addImage(['src' => 'image.png']);
$contentFragmentA->addText('$NEWVAR$');

$docx->replaceVariableByWordFragment(['VAR' => $contentFragmentA], ['type' => 'block']);

$contentFragmentB = new WordFragment($docx, 'document');
$contentFragmentB->addImage(['src' => 'image2.png']);
$contentFragmentB->addText('More content');

$docx->replaceVariableByWordFragment(['NEWVAR' => $contentFragmentB], ['type' => 'block']);

Regarding the block question, we recommend you read the documentation available on Clone blocks replacing placeholders, that details how to clone blocks replacing contents. As exaplined on this page you can add the contents to be added or use the firstMatch option.

Regards.