Forum


Replies: 3   Views: 3989
Replacevariablebytext not working in a header section
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 afoeder  · 27-01-2015 - 15:11

Hi, replacing a variableByTest does not work in some cases, the getFromZip method returns FALSE because, it seems, something's wrong with the word/header1.xml occurrence of the XPath. There is, for example, $xpathFooters = simplexml_import_dom($this->_contentTypeT); $xpathFooters->registerXPathNamespace('ns', 'http://schemas.openxmlformats.org/package/2006/content-types'); $xpathFootersResults = $xpathFooters->xpath('ns:Override[@ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml"]'); foreach ($xpathFootersResults as $footersResults) { $footer = substr($footersResults['PartName'], 1); $loadContent = $this->getFromZip($footer); … This $loadContent becomes FALSE and the subsequent code crashes because of that. $footer is "word/footer1.xml", $this->getFromZip returns FALSE because $XMLData = $zip->getFromName($src); already returns FALSE. Any ideas how to resolve this?

Posted by admin  · 27-01-2015 - 15:36

Hi, Please send to contact[at]phpdocx.com the DOCX, we'd like to check it. Regards.

Posted by afoeder  · 04-02-2015 - 16:21

For the (our) record, the error occurs when working in header or footer target and using *subsequent* invocations of replaceVariableByText, just like $docx->replaceVariableByText(array('one' => 'ONE REPLACED'), array('target' => 'footer')); $docx->replaceVariableByText(array('another' => 'ANOTHER REPLACED'), array('target' => 'footer')); "Merging" the replacement array and using only one invocation would work.

Posted by admin  · 04-02-2015 - 17:04

Hello, We have done some tests with your script and template and it's working fine on our test servers. Regards.