Forum


Replies: 1   Views: 3406
Merge docs from variables so you can test for optional merge documents
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 cem  · 08-06-2016 - 16:13

Hi,

We have the Enterprise version 5.1.  I'm wondering if you can have variables for the documents so that you either pull them in or don't if they don't exist?   If I have a possible maximum of 3 documents, but I can have anywhere between only 1 of those to all 3, is there some special conditional logic we can use?  I can test for which are not empty, but does that mean multiple options for every possible scenario or can it just skip any file it doesn't find?   I have the following rough example.  Thank you.

//doc #1 (optional)

        if (!empty($doc_one)) {

            $docx = new CreateDocxFromTemplate($doc_path.$doc1.'.docx');

            $docx->setTemplateSymbol('^');

                $variables = array(~~~~~);

            $doconefilename = 'doc1-'.time();

            $docx->replaceVariableByText($variables);

            $docx->createDocx($temp_path.$doconefilename); // create file

 

// doc #2 required

        // main template

        $docx = new CreateDocxFromTemplate($path.'doc2.docx');

        $docx->setTemplateSymbol('^');

                                $variables = array(~~~~~);

        $templatefilename = 'doc2-'.time();

        $options = array('parseLineBreaks' => true);

        $docx->replaceVariableByText($variables, $options);

        $docx->createDocx($temp_path.$templatefilename);     // create file

 

        // merge if multiple

        if (!empty($doc_one)) {

            $merge = new MultiMerge();

  $merge->mergeDocx($temp_path.$affidavitfilename.'.docx', array($temp_path.$templatefilename.'.docx'), $final_path.$final_file.'.docx', array());

Posted by admin  · 09-06-2016 - 07:10

Hello,

There's no option to do exactly what you need; we'll consider adding it in a next release. Meanwhile, we recommend you to extent the MultiMerge class and add a new method to do it.

Regards.