2014-03-19 23:08:44 +07:00
|
|
|
.. _templates:
|
|
|
|
|
|
|
|
|
|
Templates
|
|
|
|
|
=========
|
|
|
|
|
|
|
|
|
|
You can create a docx template with included search-patterns that can be
|
|
|
|
|
replaced by any value you wish. Only single-line values can be replaced.
|
|
|
|
|
To load a template file, use the ``loadTemplate`` method. After loading
|
|
|
|
|
the docx template, you can use the ``setValue`` method to change the
|
|
|
|
|
value of a search pattern. The search-pattern model is:
|
2014-03-26 15:47:27 +07:00
|
|
|
``${search-pattern}``. It is not possible to add new PhpWord elements to
|
2014-03-19 23:08:44 +07:00
|
|
|
a loaded template file.
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
2014-03-21 09:58:40 +01:00
|
|
|
.. code-block:: php
|
2014-03-19 23:08:44 +07:00
|
|
|
|
2014-03-23 17:37:26 +07:00
|
|
|
$template = $phpWord->loadTemplate('Template.docx');
|
2014-03-19 23:08:44 +07:00
|
|
|
$template->setValue('Name', 'Somebody someone');
|
2014-03-20 22:53:48 +07:00
|
|
|
$template->setValue('Street', 'Coming-Undone-Street 32');
|
|
|
|
|
|
|
|
|
|
See ``Sample_07_TemplateCloneRow.php`` for more code sample, including
|
|
|
|
|
how to create multirow from a single row in a template by using
|
|
|
|
|
``cloneRow``.
|