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();