Forum


Replies: 4   Views: 514
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 dremoussenard  · 03-08-2023 - 15:46

Hello,

the question contains two parts : is it possible and if yes, with which license.

We have a main template, and a second which contains a few block (or part of the document we can copy and keep in a variable).

We would like to open the template, doing some variables replacement, and then, depending of some data values, adding a few blocks (with variables replacement too) in the main doc.

The insertion of blocks is depending of data. As an example, we could find 5 blocks B1, B2, B3, B4 and B5 in a block template file. And one main template MT1

After creating a new doc with MT1, reading all the 5 blocks in the block template, we could insert B1 B1 B4 B1 B1 B3 B2 B1 B1 at the end of the new doc.

Is that possible?
(we alfready have a advanced license, and we could buy one more license).
Thank you,

Didier

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.

Posted by dremoussenard  · 03-08-2023 - 20:01

Hello,

ok, Thank you for the answers.

it will a new license (a new url).

the main purpuse is to produce complete word template (nice presentation, etc) in The block template, to clone them when needed. We want to use styles sheet mainly (paragraph, table, characters).

I will prepare a main template and some blocks, and a json data to show you, the result and the starting files.

didier

Posted by admin  · 03-08-2023 - 20:06

Hello,

After you have purchased the new license, please send to contact[at]phpdocx.com the sample files. We'll check them and generate a sample script. We recommend you send simple DOCX documents to illustrate how to accomplish this task; you'll be able to integrate the code in your project and work with more complex documents if needed.

Regards.

Posted by dremoussenard  · 03-08-2023 - 21:13

I have just bought thelicense.

we will send you the files tomorrow, in 12 hours.

didier