Forum


Replies: 6   Views: 88
Replacing multiple images

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();