Hello,
UPDATE: phpdocx 12 allows using the stylesReplacementType option in Premium licenses to mix existing and new styles in pPr (paragraph) and rPr (run-of-text) styles.
When you do an inline replacement using replaceVariableByWordFragment, the inline (character) styles of the placeholder are overwritten with the styles of the new content (paragraph styles remain when doing inline replacements; block replacements remove paragraph styles).
replaceVariableByText (https://www.phpdocx.com/api-documentation/templates/replace-variable-text-Word-document) doesn't overwrite placeholder styles but it doesn't allow applying new styles.
If you need to replace an inline placeholder keeping their existing inline styles and highlight it you can use the following approaches:
- Use searchAndHighlight to highlight the contents and then use replaceVariableByText to replace the placeholders by the new contents. This approach is only available in Advanced and Premium licenses.
- Use DOCXCustomizer to change styles on-the-fly of the placeholders, adding the highlight style, and then use replaceVariableByText to replace the placeholdesr by the new contents. This approach is only available in Premium licenses.
The Basic license (and also the trial one) doesn't include a method to replace a text and add new styles keeping the existing inline styles. As explained, when using replaceVariableByWordFragment with an inline replacement, existing placeholder inline styles are removed.
Regards.