Hello,
Yes, as explained in our previous reply, you can add as many contents as needed in the same WordFragment. For example, three images added as block contents (each image in its own pararagraph):
$contentFragment = new WordFragment($docx, 'document');
$contentFragment->addImage(['src' => 'image1.png']);
$contentFragment->addImage(['src' => 'image2.png']);
$contentFragment->addImage(['src' => 'image3.png']);
$docx->replaceVariableByWordFragment(['VAR_IMAGE' => $contentFragment], ['type' => 'block']);
Or three images added as inline images (in the same paragraph):
$contentFragment1 = new WordFragment($docx, 'document');
$contentFragment1->addImage(['src' => 'image1.png']);
$contentFragment2 = new WordFragment($docx, 'document');
$contentFragment2->addImage(['src' => 'image2.png']);
$contentFragment3 = new WordFragment($docx, 'document');
$contentFragment3->addImage(['src' => 'image3.png']);
$content = array();
$content[] = $contentFragment1;
$content[] = $contentFragment2;
$content[] = $contentFragment3;
$contentFragment = new WordFragment($docx);
$contentFragment->addText($content);
$docx->replaceVariableByWordFragment(['VAR_IMAGE' => $contentFragment], ['type' => 'block']);
replaceVariableByWordFragment supports doing block or inline type replacements.
We recommend you read the following documentation pages, that explains how to work with WordFragments (including samples):
- Practical guide WordFragments and WordML: https://www.phpdocx.com/documentation/practical/wordfragments-and-wordml
- Adding more than one content into a single WordFragment as block elements: https://www.phpdocx.com/documentation/snippets/adding-content-single-wordfragment-block-elements
- Adding more than one content into a single WordFragment as inline elements: https://www.phpdocx.com/documentation/snippets/adding-content-single-wordfragment-inline-elements
Regards.