Forum


Replies: 2   Views: 1476
I want to remove block labels only but $docx->clearblocks() removes label and content
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 tmm  · 14-06-2020 - 16:22

In my template I have blocks that have alternative content. I want to dynamically delete some blocks and leave the otthers.

In the code below, I am removing block content that is not applicable to the type of document. When I omit the $docx->clearBlocks(); statement, the remaining block labels and content show in the generated document. When I include the statement, the remaining block labels and content are removed.

What am I doing wrong?

    $docx = new CreateDocxFromTemplate($FH['TEMPFILEPATH']);
    $docx->setTemplateSymbol('|');
 
    $arrayValues = array();
    foreach ($Substitutions as $documentVariable) {
        $arrayValues[$documentVariable] = $row[$documentVariable];
    }
     $docx->replaceVariableByText($arrayValues);

    foreach ($BlockRules as $k=>$v) {
        if (! eval("return($v);")) {
            $docx->deleteTemplateBlock($k);
            #echo "$k:delete\n";
        }
    }
    
    $docx->clearBlocks();