Forum


Replies: 2   Views: 3663
Multiple replacevariablebyhtml not working
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 dino6213221  · 05-02-2015 - 13:15

Hi. I'm trying to replace multpile variable in word using replaceVariableByHTML function and also i'm replacing text using replaceVariableByText . If i'm only using replaceVariableByText everything is ok but adding html replacement causes troubles - doc is not generating. I was trying to replace variables only with HTML code but i can replace only one variable. Am i doing something wrong? This is my code: //$htmlData and $data are array('name' => 'value') $docx = new \CreateDocxFromTemplate($templateDir); $docx->setTemplateSymbol('‡'); $docx->replaceVariableByText($data, array()); foreach($htmlData as $key => $value){ $docx->replaceVariableByHTML($key, 'block', $value); } $filename = uniqid(); $uniqName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $filename.''; $docx->createDocx($uniqName); header( 'Content-Type: application/vnd.openxmlformats-officedocument.' . 'wordprocessingml.document' ); header( 'Content-Disposition: attachment; filename="' . $templateSymbol . '.' . $this->documentExtension . '"' ); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . filesize($uniqName . '.' . $this->documentExtension)); readfile($uniqName . '.' . $this->documentExtension);

Posted by admin  · 05-02-2015 - 13:33

Hello, Please run the included example Templates/replaceVariableByHTML/sample_1.php and check if all placeholders are replaced. And check that Tidy is enable and working. Regards.

Posted by dino6213221  · 05-02-2015 - 14:04

Hi! Thank you for help! Sample is working. I found a solution to my problem: setting template symbol to default. After this replaceVariableByText() and replaceVariableByHtml() works great.