Forum


Replies: 5   Views: 3925
Clone block and replace content
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  · 03-08-2018 - 16:02

Hello,

What version and license of phpdocx are you using?

Anyway, the code is working with the data you are adding. You are replacing all placeholders (with the same name):

$docx->replaceVariableByHtml('dynamic', 'block', $item);

with the same value. If you need to replace only the first one, you need to use the firstMatch option:

foreach ($datas as $key => $item) {
    $docx->replaceVariableByHtml('dynamic', 'block', $item, array('firstMatch' => true));
}

Using this option you can iterate an array, the first placeholder of the template is replaced, then the second one (as the first placeholder doesn't exist, this second placeholder is now the first occurrence) and so on.

Regards.