Forum


Replies: 2   Views: 1543
Consistent way to read list variables
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  · 23-06-2020 - 14:47

Hello,

UPDATE: phpdocx 13.5 added getTemplateVariablesType to get the type of template variables.

Using getDocxPathQueryInfo you can query by many content types, such as list type, for example using the file TemplateList.docx included in the package:

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

$referenceNode = array(
    'type' => 'list',
);

$queryInfo = $docx->getDocxPathQueryInfo($referenceNode);

foreach ($queryInfo['elements'] as $element) {
    var_dump($element->textContent);
}

You can iterate the elements key and get each value using the textContent attribute, that removes the tags to get the value of each result and returns the value of each list paragraph (in a DOCX a list is a paragraph with some specific w:numPr and w:ilvl tags). Using this code you can iterate the elements to get only those strings that contain the symbols uses to wrap the placeholders ($ as default).

Regards.