Forum


Replies: 1   Views: 1205
Replacelistvariable didn't create list
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  · 20-05-2021 - 05:08

Hello,

The replaceListVariable method adds list items to an existing list in a template, removing the placeholder and adding new list items. We think you are using replaceListVariable with a placeholder that it's not in a list. We recommend you to check the included samples and the documentation available on https://www.phpdocx.com/api-documentation/templates/replace-list-variable-Word-document.

If you need to replace a placeholder (that it's not in a list) by a list, you need to use replaceVariableByWordFragment, for example using a template included in the package:

$docx = new CreateDocxFromTemplate('examples/files/TemplateSimpleText.docx');

$itemList = array(
    'Line 1',
    'Line 2',
    'Line 3',
    'Line 4',
    'Line 5'
);

$listWordFragment = new WordFragment($docx, 'document');
$listWordFragment->addList($itemList, 1);

$docx->replaceVariableByWordFragment(array('MULTILINETEXT' => $listWordFragment));
$docx->createDocx('output.docx');

We recommend you to read the following documentation pages:

Regards.