Forum


Replies: 6   Views: 305
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 fiwoyax200  · 25-04-2024 - 10:37

Thanks for the response.

I have a Word document with a text placeholder of $IMAGE$. How would I be able to use replaceVariableByWordFragment to replace and add multiple images.

I have tried a work around using cloning blocks to create more than one placeholder, however, it just results in the first image being replaced by them all.

$BLOCK_FIRST$
$IMAGE$
$BLOCK_FIRST$
$docx->cloneBlock('FIRST');
$imageFragment = new WordFragment($docx, 'document');
$imageFragment->addImage(['src' => 'reports/Img/237/662834ac2885f.png'], $ImageProperties);
$docx->replaceVariableByWordFragment(['IMAGE' => $imageFragment], ['type' => 'block']);


$docx->cloneBlock('FIRST');
$imageFragment = new WordFragment($docx, 'document');
$imageFragment->addImage(['src' => 'reports/Img/237/662976a4c1b05.jpg']);
$docx->replaceVariableByWordFragment(['IMAGE' => $imageFragment], ['type' => 'block']);
$docx->cloneBlock('FIRST');
$docx->clearBlocks();