Forum


Replies: 6   Views: 901
Using cloneblock to clone elements
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  · 10-05-2022 - 05:40

Hello,

Please note that the second parameter in the cloneBlock method is the following:

occurrence      Position of the block to be cloned. 1 as default.

that is the occurrence of the placeholder to be cloned, not the number of times to be cloned.

When your code does:

$word_object->cloneBlock("CONTACT_PERSONS", 5);

it tries to clone the fifth position of the block CONTACT_PERSONS in the document.

Also note that cloneBlock works with elements in the same level (sibling elements between the block placeholders). You can't use cloneBlock with the first block placeholder added in a row in a table and the end block placeholder added in another row; they must be added as siblings of the same parent. If this is your case, you need to use the cloneWordContent method included in DOCXPath.

If you send your DOCX to contact[at]phpdocx.com we can generate a sample script.

Regards.