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:51

I have created a new docx from template with mulitple variables.

Then, in the new docx, i need to add an external templates (this is working fine)

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

But now, I need to replace variable by text in the external file.

I have already tried to : 

1. create an array for the external files variables :

  $variableForExternaFile = 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']

        );

2. create a second docx from template for the external file

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

3. replace the variable by text  in the external files 

  $externalFile ->replaceVariableByText($variableForExternaFile );

4. finally replaceVariableByExternalFile in the new docx (external files) 

 $docx->replaceVariableByExternalFile(array('EXTERNALFILE' => $externalFile ), array('matchSource' => true));

But not working.

 

Do I have a solution with phpdocx?