processTemplate

processTemplate

TRIAL / ADVANCED / PREMIUM

Preprocesses a given Word template in order to speed up further manipulations over it.

Description
public processTemplate (array $variables)

This method allows the preprocessing of a Word template in order to improve performance in the process of replacing placeholder variables by their corresponding values.

Due to various reasons the Word interface may split internally the placeholder variables making direct substitution impossible. Even if you may see the placeholder variable correctly displayed in the Word interface the associated XML node may contain the associated text included in a very cumbersome way (with XML tags splitting the variable name in different chunks).

Although phpdocx deals by itself with that extra complications the process may require multiple manipulations, which for documents with a very large number of placeholders variables, may considerably slow down the output.

By preprocessing the Word template you make sure that all variables are already properly cleaned so the substitution may be carried out at a very fast pace.

It is convenient to run this method independently and keep the resulting document in a separate repository of processed templates.

If the placeholders use delimiter symbols that exist in other contents of the document, it is advisable to indicate the name of the variables that are going to be processed instead of automatically detect them.

Parameters

variables

You may try to generate automatically this array with the getVariables method although it is highly recommended to have a look at the resulting array to make sure that it includes all the relevant variables in the expected format.

options

The keys and values of this array are:

Key Type Description
document array Array of variable names within the main document.
headers array Array of variable names within the headers of the document.
footers array Array of variable names within the footers of the document.
footnotes array Array of variable names within the footnotes of the document.
endnotes array Array of variable names within the endnotes of the document.
comments array Array of variable names within the comments of the document.
Code samples

Example #1

Release notes
  • phpdocx 10.0:
    • supported singular nouns to set targets.