Replies: 7   Views: 1140
Insert link with the same formatting like common text
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by Exorion  · 08-05-2021 - 20:37

Hi guys! 

I have 20 templates with different styles. I load is as a template with variables. If i replace variable with text all formating is still the same. But if i add a Link as a wordFragment and replace it with template variable - my formating seems different. Is it a way how i can make it looks the same?


Posted by admin  · 09-05-2021 - 08:14


The replaceVariableByText method keeps existing styles when replacing placeholders.

Using the replaceVariableByWordFragment method, If the styles are applied to the paragraph (w:pPr styles), when you do an inline replacement the existing styles remain, but if the styles are applied to the placeholder (w:rPr styles), then replacing the placeholder by a WordFragment the styles will be changed to use the styles from the WordFragment. Premium licenses include options to keep and mix existing styles when replacing a placeholder in complex replacements, for example replaceVariableByHTML includes the stylesReplacementType option:

stylesReplacementType     string   Empty as default. Only available in Premium licenses.

* usePlaceholderStyles: keeps placeholder styles, styles from the imported HTML are ignored. Applies to the following styles: pPr, rPr.

* mixPlaceholderStyles: mixes placeholder styles, placeholder styles overwrite HTML styles with the same name. Applies to the following styles: pPr, rPr.

Since phpdocx 9, Advanced and Premium licenses also include getWordStyles. This method can be used for example to get existing styles from a placeholder and apply them to the WordFragment to be added.

We recommend you to upgrade to the latest Premium version, so you can do complex replacements to mix and keep styles when replacing placeholders by HTML and WordFragments.


Posted by Exorion  · 09-05-2021 - 11:23

I have 10 version on other login ( and i try to use getWordStyles - but then it's inside a table, i can't find it in a table-cell, even if a 'parent' => 'w:tbl/w:tr/', i can find it with 'run' type - but it seems not right. How i can search more?

Posted by admin  · 09-05-2021 - 18:51


If the style is set to the placeholder (not as paragraph style) you need to get the w:rPr styles of that placeholder.

If you open a support ticket ( attaching a sample DOCX the dev team will generate a custom script using it to illustrate the specific task with your document.


Posted by Exorion  · 09-05-2021 - 19:53

The run type is working fine - i just check on 10 documents, what type should i use to search content in rPr paragraph?


Posted by admin  · 10-05-2021 - 07:00


If the styles are applied to the placeholder you need to query w:rPr styles. If the styles are applied to the paragraph you need to query w:pPr styles.


Posted by Exorion  · 10-05-2021 - 09:57

and what should i write in a 'type' option?

Posted by admin  · 10-05-2021 - 10:27


The type value to be used depends on how the styles are being applied. For example, if the styles are applied as w:rPr to a w:r tag (run content), then you need to set run as type.

We recommend you to check the samples included in the package: samples/DocxPath/getWordStyles.