Forum


Replies: 2   Views: 2307
Table issue when try to clone block
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  · 04-12-2017 - 11:50

Hello,
 
Thank you very much for your files. You're right, there's a minor bug in the file that hasn't been detected until you have sent your files: a variable is not being initialized correctly. This issue only appears when there's more than one table with the same placeholder values.
 
Although it could be accomplished using DOCXPath or the MultiMerge classes without changing anything in the current version of the library, the dev team has generated a small patch that will be included in the next release of phpdocx.
 
As you are using the namespaces package (although the same line can be added to the classic package), please edit the Classes/Phpdocx/Create/CreateDocxFromTemplate.inc file and in line 886 add this line:
 
$tableCounter = 0;

Instead of this code:

foreach ($vars as $key => $rowValue) {
    foreach ($foundNodes as $node) {
        $domNode = dom_import_simplexml($node);
        if (!is_object($referenceNode) || !$domNode->parentNode->isSameNode($parentNode)) {
            $referenceNode = $domNode;
            $parentNode = $domNode->parentNode;
            $tableCounter++;
        }
This is the correct code:
foreach ($vars as $key => $rowValue) {
    $tableCounter = 0;
    foreach ($foundNodes as $node) {
        $domNode = dom_import_simplexml($node);
        if (!is_object($referenceNode) || !$domNode->parentNode->isSameNode($parentNode)) {
            $referenceNode = $domNode;
            $parentNode = $domNode->parentNode;
            $tableCounter++;
        }

After this small fix you us the cloneBlock with tables using the replaceTableVariables method.

Our apologize for any inconvenience. This change is being fully tested to be added in the next stable release of the library.

Regards.