Forum


Replies: 1   Views: 1145
Replacevariablebyhtml using block parameter replaces the entire line of the variable
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 dipeshc  · 19-07-2021 - 08:25

Hello,

I facing the problem when I use replaceVariableByHTML using block parameter replaces the entire line of the variable.

e.g:

// my word file content (document.docx)
/*
Item name: My item
Item Description: $DESCRIPTION$
Price: 999
*/

// and my item description is
$description = 'The Item features a stylish design and <span style="color:orange">innovative</span> features so that you can enjoy using the mobile phone for all that you need.
<br><br>
Warranty card, User guide, Clear soft case, Screen protector are included';

$docx = new CreateDocxFromTemplate('document.docx');

$docx->replaceVariableByHTML('DESCRIPTION', 'block', $description, array('isFile' => false, 'downloadImages' => false));

$docx->createDocx('output');

Problem:

The above code replaces the entire line(Item description line) with the $description.

But I want to keep the Item Description: as well.

I know we can use inline in the second parameter of the replaceVariableByHTML function but I want to use block instead.

Incorrect output:

Item name: My item
The Item features a stylish design and <span style="color:orange">innovative</span> features so that you can enjoy using the mobile phone for all that you need.


Warranty card, User guide, Clear soft case, Screen protector
Price: 999

Expected output:

Item name: My item
Item Description: The Item features a stylish design and innovative features so that you can enjoy using the mobile phone for all that you need.


Warranty card, User guide, Clear soft case, Screen protector are included.
Price: 999