Hello,
By default, phpdocx allows using a single symbol ($, #, |...) or ${ } to wrap placeholders.
Using a not unique placeholder distinct than ${ }, such as #{ }, {{ }}, [], [[]]... requires customizing the static variable CreateDocxFromTemplate::$regExprVariableSymbols. You can read this same information on the documentation page of the setTemplateSymbol method (https://www.phpdocx.com/api-documentation/templates/set-Word-template-placeholder-variable-symbol):
Different at the beginning and the end: ${VAR}. phpdocx requires using ${ } to wrap placeholders that don't use the same symbol at the beginning and the end, to use other symbols the public static variable CreateDocxFromTemplate::$regExprVariableSymbols must be customized.
CreateDocxFromTemplate::$regExprVariableSymbols is a public static variable with a regular expression that must match the symbols you want to use to wrap placeholders (as this is a regular expression, please note you need to escape protected characters in regular expressions such as [ ]).
We recommend using the default symbols to wrap placeholders:
- A single symbol (1 byte character): $VAR$, #VAR#, |VAR|...
- Or ${ }: ${VAR}
As explained previously, using not unique simbols different to the default ${ } require customizing CreateDocxFromTemplate::$regExprVariableSymbols, for example, the following code:
CreateDocxFromTemplate::$regExprVariableSymbols = '\[.*\]';
$docx->setTemplateSymbol('[', ']');
print_r($docx->getTemplateVariables());
sets [ ] as symbols to wrap placeholders. Please note that this custom code may require some minor adjustments to get the exact regular expression to be used in your templates, for example to exclude [ if you add it as other content in the document:
CreateDocxFromTemplate::$regExprVariableSymbols = '\[[^\[]*\]';
This custom regular expression is required to clean splitted placeholders across XML nodes with processTemplate (this method is called automatically by phpdocx) when not using the default settings (a single symbol or ${ } to wrap placeholders).
Regards.