Forum


Replies: 4   Views: 517
How to read blocks from a first template and to insert them when needed in new doc
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-2023 - 16:44

Hello,

Yes, it's possible to do the requested task with phpdocx. To accomplish it we recommend you use a phpdocx Premium license.

As you are using two templates (a main template and another template with blocks that can be cloned as many as times as needed), you can:

  • Use importContents to import specific contents (blocks in your case, this method uses mergeDocx internally to import contents) into the main document from an external DOCX. You can use this method as many times as needed.
  • Or use mergeDocx to merge the documents and then use DOCXPath methods to clone and move the block contents.
  • Or, if the block contents to be imported doesn't have external relationships (such as images, links or charts) and the main template already includes all styles to be used, you can use DOCXPath to get the XML contents and then use addWordML to inject the WordML into the main template.

The best approach depends on the contents to be imported. We can generate a sample script to illustrate how to do the three approaches, and if you send two sample templates (the main template and a DOCX with the blocks), we'll generate the sample script using them.

Regards.