Hello,
Please note that the importHeadersAndFooters method may not generate the exact output in your case because the setDefault option changes all targets, including the "even" position in headers/footers.
For this specific case, we recommend using the DOCXCustomizer approach detailed in our previous reply.
Regarding the importHeadersAndFooters method, please note that this is a CreateDocx method (although CreateDocxFromTemplate inherits it).
In this case, the imported headers and footers are not available unless you load the DOCX containing the imported headers and footers as a new template:
$docx = new CreateDocxFromTemplate('sample_1_upd.docx');
$wordTemplateVariablesArray = $docx->getTemplateVariables();
$docx->importHeadersAndFooters('sample_1_upd.docx', 'headerAndFooter', ['setDefault' => true]);
$docx->createDocx('sample_1_upd_importHeadersAndFooters');
$docx = new CreateDocxFromTemplate('sample_1_upd_importHeadersAndFooters.docx');
$wordTemplateVariablesArray = $docx->getTemplateVariables();
$docx->createDocx('output');You could also use in-memory DOCX (https://www.phpdocx.com/documentation/cookbook/in-memory-docx-documents) to avoid generating temp files:
$docx = new CreateDocxFromTemplate('sample_1_upd.docx');
CreateDocx::$returnDocxStructure = true;
$wordTemplateVariablesArray = $docx->getTemplateVariables();
$docx->importHeadersAndFooters('sample_1_upd.docx', 'headerAndFooter', ['setDefault' => true]);
$docxStructureTemplate = $docx->createDocx();
CreateDocx::$returnDocxStructure = false;
$docx = new CreateDocxFromTemplate($docxStructureTemplate);
$wordTemplateVariablesArray = $docx->getTemplateVariables();
$docx->createDocx('output');We have forwarded this task to the dev team to improve this workflow in future releases of phpdocx.
Regards.