replaceVariableByWordFragment
- addBibliography
- addBookmark
- addBreak
- addChart
- addCitation
- addComment
- addCrossReference
- addDateAndHour
- addEndnote
- addExternalFile
- addFootnote
- addFormElement
- addHeading
- addImage
- addLink
- addList
- addMathEquation
- addMergeField
- addOLE
- addOnlineVideo
- addPageNumber
- addShape
- addSimpleField
- addSource
- addStructuredDocumentTag
- addSVG
- addTab
- addTable
- addTableContents
- addTableFigures
- addText
- addTextBox
- addWordFragment
- addWordML
- embedHTML
- addBackgroundImage
- addFooter
- addFooterSection
- addHeader
- addHeaderSection
- addLineNumbering
- addMacroFromDoc
- addPageBorders
- addProperties
- addSection
- createDocx
- createDocxAndDownload
- createCharacterStyle
- createListStyle
- createParagraphStyle
- createTableStyle
- docxSettings
- embedFont
- importChartStyle
- importHeadersAndFooters
- importListStyle
- importStyles
- importStylesWordDefault
- modifyPageLayout
- parseStyles
- removeFooters
- removeHeaders
- setBackgroundColor
- setDecimalSymbol
- setDefaultFont
- setDocumentDefaultStyles
- setEncodeUTF8
- setLanguage
- setMarkAsFinal
- setRTL
- clearBlocks
- cloneBlock
- deleteBlock
- getTemplateVariables
- getTemplateVariablesType
- modifyInputFields
- modifyMergeFields
- processTemplate
- removeTemplateVariable
- removeTemplateVariableImage
- replaceBlock
- replaceListVariable
- replacePlaceholderImage
- replaceTableVariable
- replaceVariableByExternalFile
- replaceVariableByHtml
- replaceVariableByText
- replaceVariableByWordFragment
- replaceVariableByWordML
- setTemplateSymbol
- setTemplateBlockSymbol
- tickCheckboxes
replaceVariableByWordFragment
Replaces placeholder variables by fragments of Word.
This powerful method allows the substitution of placeholder variables by Word fragments that may include:
- formatted text
- tables
- images
- charts
- footnotes
- ...
The Word fragments should be instances of the WordFragment class.
The available WordFragment targets to be used with this method are the following: body of the document ('document'), headers ('header'), footers ('footer'), footnotes ('footnote'), endnotes ('endnote') and comments ('comment'). Specific header and footer targets such as defaultHeader or firstFooter aren't used.
variables
This must be an array with the names of the placeholder template variables as keys and the WordFragment instances that should replace them as values.
options
The possible keys and values of this array are:
Key | Type | Description |
---|---|---|
firstMatch | boolean | If the variable appears more than once within the Word document and firstMatch is set to true, phpdocx will only replace the first occurrence of the variable within the Word document. |
stylesReplacementType | string |
Empty as default.
Only available in Premium licenses. |
stylesReplacementTypeIgnore | array | Styles to be ignored from the imported WordFragment. Use with mixPlaceholderStyles. Empty as default. Only available in Premium licenses. |
stylesReplacementTypeOverwrite | bool | If true, WordFragment styles overwrite placeholder styles with the same name that are not set in the stylesReplacementTypeIgnore option. Use with mixPlaceholderStyles. Default as false. Only available in Premium licenses. |
target | string | Possible values are: document (default), header, footer, footnote, endnote, comment. This option sets the scope of the replacement procedure. |
type | string | Possible values are:
|
Not using WordFragments.
- phpdocx 15.0:
- improved the inline-block replacement type to work with complex contents multiple times.
- phpdocx 13.5:
- stylesReplacementTypeOverwrite option.
- phpdocx 12.5:
- inline-block replacement type can be used with the same placeholder name more than once.
- improved inline type replacements to keep existing rPr styles in contents after placeholders.
- phpdocx 12.0:
- stylesReplacementType option.
- inline-block type replacement.
- phpdocx 7.0:
- improved performance working with headers and footers.
- phpdocx 4.6:
- header and footer targets.