Нема описа

templates-processing.rst 1.3KB

12345678910111213141516171819202122232425
  1. .. _templates-processing:
  2. Templates processing
  3. ====================
  4. You can create a .docx document template with included search-patterns which can be replaced by any value you wish. Only single-line values can be replaced.
  5. To deal with a template file, use ``new TemplateProcessor`` statement. After TemplateProcessor instance creation the document template is copied into the temporary directory. Then you can use ``TemplateProcessor::setValue`` method to change the value of a search pattern. The search-pattern model is: ``${search-pattern}``.
  6. Example:
  7. .. code-block:: php
  8. $templateProcessor = new TemplateProcessor('Template.docx');
  9. $templateProcessor->setValue('Name', 'Somebody someone');
  10. $templateProcessor->setValue('Street', 'Coming-Undone-Street 32');
  11. It is not possible to directly add new OOXML elements to the template file being processed, but it is possible to transform main document part of the template using XSLT (see ``TemplateProcessor::applyXslStyleSheet``).
  12. See ``Sample_07_TemplateCloneRow.php`` for example on how to create
  13. multirow from a single row in a template by using ``TemplateProcessor::cloneRow``.
  14. See ``Sample_23_TemplateBlock.php`` for example on how to clone a block
  15. of text using ``TemplateProcessor::cloneBlock`` and delete a block of text using
  16. ``TemplateProcessor::deleteBlock``.