Forum


Replies: 3   Views: 357
How to add variables in an external file
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 ElodieMllr  · 18-04-2023 - 09:59

Resolved :

 

I have first get the external template, then insert the variables and create a copy with the variables.

Finally, insert the new template with the variables in my docx

 

  $externalDocx = new CreateDocxFromTemplate(public_path() . '/templates/external file.docx');


 

        $externalVariables = array(

            'TIMEESTIMATED' => $request->get('DescriptionSheet')['timeEstimated'],

            'HOURLYRATE' => $request->get('PriceInfo')['hourPrice'],

            'TOTALCOST' => $request->get('PriceInfo')['totalCoast'],

            'DISCOUNT' => $request->get('PriceInfo')['reductionAmount'],

            'HOURLYRATEDISCOUNT' => $request->get('PriceInfo')['hourlyRateDiscounted']

        );

        $externalDocx->replaceVariableByText($externalVariables );

        $externalDocx->createDocx(public_path() . '/templates/external file edit.docx');

 

        $docx->replaceVariableByExternalFile(array('EXTERNALFILE' => public_path() . '/templates/external file edit.docx'), array('matchSource' => true));