Forum


Replies: 7   Views: 2208
Docx template
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 kpholland  · 25-02-2016 - 15:41

Where are using the $docx->addTemplate('test.docx'); template function.

$docx->addTemplateVariable('Name', ''.$name.''); 

Now we want to create a dynamic table in the template (with four rows and dynamic colums)

which function can and must we use. We have version 5.X

Posted by admin  · 25-02-2016 - 16:24

Hello,

The methods addTemplate and addTemplateVariable doesn't exist in phpdocx 5, only in phpdocx 3 and previous versions. With phpdocx 5 you need to use the CreateDocxFromTemplate class to open the DOCX template and then use addTable (http://www.phpdocx.com/api-documentation/word-content/add-table-Word-document-with-PHP) to add a new table at the end of the document or replaceVariableByWordFragment (http://www.phpdocx.com/api-documentation/templates/replace-variable-word-fragment-Word-document) to replace a placeholder by a table.

Regards.

Posted by kpholland  · 26-02-2016 - 08:35

Thank you for the answer. Where are upgrading from version 3 to version 5. What the replacement for the version 3 command: $docx->addTemplateVariable('VarTemplate', ''.$Vartemp.'');

We want to replace some variables in our template

Posted by kpholland  · 26-02-2016 - 08:55

I found the answer :) replaceVariableByText

But how can i insert a complete table in the middle of a template? replaceVariableByText doesn't work...The table is put on the end of the Word template...

$docx->addTable($Array_Table, $paramsTable);

 

 

 

Posted by kpholland  · 26-02-2016 - 09:17

Thank you for the help file.

I only have one problem....The $docx->addTable($Array_Table, $paramsTable); is working in the template, only the table is set at the end of the output docx. Is it possible to set some coordinates for the table in the template file.

 

Posted by admin  · 26-02-2016 - 09:42

Hello,

You could replace an existing placeholder in the template by a table using WordFragments and the replaceVariableByWordFragment method.

Regards.

Posted by kpholland  · 26-02-2016 - 10:34

It is working. This is the solutions

$wf = new WordFragment($docx, 'document');
$wf->addTable($Array_Table_Value, $paramsTable);
$docx->replaceVariableByWordFragment(array('Array_Table_Value' => $wf), array('type' => 'block'));