Forum


Replies: 6   Views: 88
Replacing multiple images

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.