Forum


Replies: 5   Views: 2713
Need to add two or more merge fields on same line
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  · 13-03-2018 - 07:31

Hello,

You need to use phpdocx 7.5 and WordFragments. For example:

$docx = new CreateDocx();

$mergeField1 = new WordFragment($docx);
$mergeField1->addMergeField('MyMergeField1', null, array('underline' => 'dash'));

$mergeField2 = new WordFragment($docx);
$mergeParameters = array(
    'textBefore' => 'A mergefield example: ', 
    'textAfter' => ' and some text afterwards.'
);
$mergeField2->addMergeField('MyMergeField2', $mergeParameters, array('color' => 'B70000'));

$text = array();
$text[] = $mergeField1;
$text[] = array(
    'text' => ' ',
);
$text[] = $mergeField2;

$docx->addText($text);

$docx->createDocx('document');

Regards.