Forum


Replies: 4   Views: 4051
Html and replacetablevariable
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 dthomas41  · 21-07-2015 - 05:25

We are currently evaluating phpdocx for replacing paper forms and need to embed HTML within tables in a template. The tutorial which explains how to do this no longer works. I tried the following code but it does not render anything in the cell marked $html$. $docx = new CreateDocxFromTemplate('../templates/test.docx'); $wf = new WordFragment($docx); $html = '
  • Item 1
  • Item 2
'; // My HTML was removed by the forum code. $htmlFragment = $wf->embedHTML($html); $data = array( array('name' => 'Example name', 'number' => 12345, 'html' => $htmlFragment) ); $docx->replaceTableVariable($data);

Posted by admin  · 21-07-2015 - 07:32

Hi there, the embedHtml() method returns nothing, and that's why your code does not render anything, because $htmlFragment is null. Change these lines: $htmlFragment = $wf->embedHTML($html) to this $wf->embedHTML($html), and $data = array( array('name' => 'Example name', 'number' => 12345, 'html' => $htmlFragment) ); to this $data = array( array('name' => 'Example name', 'number' => 12345, 'html' => $wf) );

Posted by dthomas41  · 21-07-2015 - 23:03

Hi Admin, Thanks for your reply. Unfortunately your code doesn't appear to work. I'm left with the third cell full of WordML markup. :(

Posted by admin  · 22-07-2015 - 07:01

Hi there, the code post is correct and you need to use if you want to use a wordfragment correctly. Anyway you are right, you code is not working because there is another mistake, the replaceTableVariable does not support wordFragments at the moment, I have not noticed that. If you want to replace any variable by wordfragment you need to use the replaceVariableByWordFragment method Regards.

Posted by dthomas41  · 22-07-2015 - 23:20

Hi admin, While that does work, it does not really solve my problem. As I need to populate 1 to n rows of tables in my template, I have found a workaround which involves using replaceTableVariable to create 1 to n rows with temporary variables then calling replaceVariableByHTML. It would be great if replaceTableVariable supported HTML and/or word fragments. Do you have any intention to fix it as it appears it was supported in older versions?