Forum


Replies: 1   Views: 441
Replacevariablebywordfragment multiline
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 apalou  · 19-09-2022 - 17:12

I'm trying to user the function with a multilne html and doesn't work.... no line breaks...

Thanks,

Posted by admin  · 19-09-2022 - 17:49

Hello,

What method are you using? replaceVariableByHTML or replaceVariableByWordFragment?

In any case, both methods add line breaks correctly.

For example, using replaceVariableByHTML:

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

$docx->replaceVariableByHTML('VAR', 'block', '<p>A new content<br> and more content</p>');

Or using replaceVariableByWordFragment:

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

$htmlWordFragment = new WordFragment($docx, 'document');
$htmlWordFragment->embedHTML('<p>A new content<br> and more content</p>');
$docx->replaceVariableByWordFragment(array('VAR' => $htmlWordFragment));

In both cases the variable is replaced correctly by the new HTML and the line breaks are added correctly.

Please post the most simple code you are running so we can check it. Please note that HTML requires adding br tags to generate line breaks or using block contents. "\n" or "\r\n" breaks can't be used when transforming HTML. These newline characters can be used with other template methods such as replaceVariableByText setting the parseLineBreaks option as true.

Regards.