Forum


Replies: 5   Views: 4161
Lib crashes when i try to replace a variable and a placeholder (both in header)
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 jdespatis  · 15-07-2014 - 10:32

I have a template with an image placeholder in the header ($HEADERIMG$), and a variable in the header ($FOO$) (screenshot of this template: http://screencast.com/t/Ruf9EGNb) Then if I want to replace FOO and then HEADERIMG, with following code: $docx = new \CreateDocxFromTemplate("replacePlaceholderImages2.docx"); $docx->replaceVariableByText(array("FOO" => 4), array("target" => "header")); $docx->replacePlaceholderImage('HEADERIMG', 'images/user.png', array("target" => "header")); $docx->createDocx('/tmp/example_replacePlaceholderImages_2'); => I get an exception: ContextErrorException: Warning: DOMDocument::loadXML(): Empty string supplied as input in [...]/phpdocx/classes/CreateDocxFromTemplate.inc line 1096 As a second try, if I want to replace the placeholder HEADERIMG and then the variable FOO, with following code: $docx = new \CreateDocxFromTemplate("replacePlaceholderImages2.docx"); $docx->replacePlaceholderImage('HEADERIMG', 'images/user.png', array("target" => "header")); $docx->replaceVariableByText(array("FOO" => 4), array("target" => "header")); $docx->createDocx('/tmp/example_replacePlaceholderImages_2'); => I get an exception: FatalErrorException: Error: Call to a member function registerXPathNamespace() on a non-object in [...]/phpdocx/classes/CreateDocxFromTemplate.inc line 1271 Am I using the lib in a bad manner ? Thanks for your feedback