After some absolutely unparallelled support (thanks) .. this is the answer (should anyone need it)
The problem comes from how placeholders and the preprocessed option are handled with clone blocks.
There're two easy approaches to solve the issue:
- handle the preprocessed option after the template is loaded . We have added two lines to your code:
$docx = new CreateDocxFromTemplate('templateName.docx');
$docx->processTemplate($docx->getTemplateVariables());
CreateDocxFromTemplate::$_preprocessed = true;
$docx->replaceVariableByText($values);
- generate optimize templates to work with them. We recommend you to use this approach, as it returns the best performance (you don't need to call processTemplate for each template when you load it, you can use the optimized templates directly). Instead of using not cleaned templates, you can generate optimize templates:
$docx = new CreateDocxFromTemplate('templateName1.docx');
$docx->processTemplate($docx->getTemplateVariables());
$docx->createDocx('templateName1_optimized.docx');
$docx = new CreateDocxFromTemplate('templateName2.docx');
$docx->processTemplate($docx->getTemplateVariables());
$docx->createDocx('templateName2.docx');
You just need to run the previous code one for each template.
Then you can use the new files (that are optimized) directly in your scripts instead of the old ones, setting the preprocessed option as true when loading them:
$templates = array(
'templateName1_optimized'', 'templateName2_optimized',
);
(...)
$docx = new CreateDocxFromTemplate($templates[$ii].'.docx', array('preprocessed' => true));
$docx->replaceVariableByText($values);