Replies: 5   Views: 2779
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  · 13-03-2018 - 04:23

Hello Team,

I need to add two or more merge fields on single line.

Like:  Address <<address_line_1>>, <<address_line_2>>, <<address_line_3>>

I tried using addMergeField() but it's not working as expected.

Output is like below:








Can you please help me for same.




Posted by admin  · 13-03-2018 - 07:31


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;




Posted by  · 13-03-2018 - 08:15

Hi Team,

I used the code, suggested by you.

It gives result as expected like two or merge fields on same line, but the properties of merge fields are lossed.

Please help me for same.


Posted by admin  · 13-03-2018 - 09:16


That is available since the release of phpdocx 7.5. What version and license of phpdocx are you using?


Posted by  · 13-03-2018 - 09:26


We are using version 7.

We have purchased license for domain




Posted by admin  · 13-03-2018 - 09:37


Sorry but that feature is not available for phpdocx 7.0, only for phpdocx 7.5 (and newer when new releases of phpdocx appear).

If you have the LUS ( for your license you can download the latest package on MY PHPDOCX after login. Otherwise, you can upgrade your license on this same page. We have tested the previous script with phpdocx 7.5 and all merge field styles and properties keep.