Forum


Replies: 5   Views: 2918
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 gmane@xento.com  · 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:

Address

<<address_line_1>>

,

<<address_line_2>>

,

<<address_line_3>>

 

Can you please help me for same.

Thanks

 

 

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.

Posted by gmane@xento.com  · 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.

Thanks

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

Hello,

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

Regards.

Posted by gmane@xento.com  · 13-03-2018 - 09:26

Hi,

We are using version 7.

We have purchased license for domain entrata.com

Thanks

 

 

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

Hello,

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 (https://www.phpdocx.com/updates) 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.

Regards.