Forum


Replies: 2   Views: 4030
Replace image in a template table
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 Simplexe  · 26-07-2016 - 12:59

hello,

I use CreateDocxFromTemplate() class
I have a table with 3 columns in this template and i want to replace variables with some data.
but the third column is an image which is different on each line

It could be like this code :

<?php

$docx = new CreateDocxFromTemplate('TemplateSimpleTable.docx');

$data = array(
            array(
                'ITEM' => 'Product A',
                'REFERENCE' => '107AW3',
                'IMAGE' => '<img src="http://www.w.javadocx.com/img/logo_badge.png" />'
            ),
            array(
                'ITEM' => 'Product B',
                'REFERENCE' => '204RS67O',
                'IMAGE' => '<img src="http://www.w.javadocx.com/img/preview/phpdocx_box_corporate.png" />'
            ),
            array(
                'ITEM' => 'Product C',
                'REFERENCE' => '25GTR56',
                'IMAGE' => '<img src="http://www.w.javadocx.com/img/preview/phpdocx_box_enterprise.png" />'
            )
        );

$docx->replaceTableVariable($data, array('parseLineBreaks' => true));

?>

but i don't know if :

- replaceTableVariable method can support HTML code instead of basic text

- replaceVariablebyHTML can work on template table (as replaceTableVariable does)

- maybe i have to create wordFragment for each "IMAGE" value in $data php array

thanks for help

regards