JSON API - replaceVariableByHTML

replaceVariableByHTML

PREMIUM TRIAL / ADVANCED

Replaces a single variable by HTML.

Note

You are reading the JSON API documentation. For the PHP API method please go to replaceVariableByHTML.

JSON data
Key Description
variable The template variable to be replaced by the HTML content.
type Replacement type: block (default) or inline.
html The HTML code to be translated into WordML.
addDefaultStyles True as default, if false prevents adding default styles when strictWordStyles is false.
addDefaultStylesPpr True as default, if false prevents adding default pPr styles when strictWordStyles is false.
addDefaultStylesRpr True as default, if false prevents adding default rPr styles when strictWordStyles is false.
baseURL The base URL used to complete the relative paths of links and images.
cssEntityDecode If true uses html_entity_decode to parse CSS, useful when using font families with non-ASCII names.
customListStyles If true checks if there is a custom list style with that name and uses it.
disableWrapValue If true disable using a wrap value with Tidy to prevent extra blank spaces. Default as false.
downloadImages If true inserts the images into the docx document, otherwise just links them as an external source.
embedFonts If true downloads and embeds TTF fonts from @font-face rules. False as default. Only available in Premium licenses.
filter Only renders the filtered contents. It could be an string denoting an id ('#myId'), a class ('.myClass'), a HTML tag or a valid XPath expression ('//expression').
forceNotTidy False as default. If true, avoid using Tidy. Only recommended if Tidy can't be installed.
generateCustomListStyles If true generates automatically the custom list styles from the list styles (decimal, lower-alpha, lower-latin, lower-roman, upper-alpha, upper-latin, upper-roman).
parseAnchors If true parses the anchors included in the HTML code.
parseCSSVars If true parses CSS variables.
parseDivs paragraph or table. By default the method parses the div elements as containers.
parseFloats If true preserves the floating properties of images and tables.
removeLineBreaks If true removes extra line breaks that can be generated when transforming HTML that includes strings without a parent tag.
strictWordStyles If true ignores almost all CSS styles and uses the styles set via the wordStyles option (see next).
stylesReplacementType

Empty as default.

  • 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.
stylesReplacementTypeIgnore

Styles to be ignored from the imported HTML. Use with mixPlaceholderStyles. Empty as default.

stylesReplacementTypeOverwrite

If true, HTML 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 Possible values are: document (default), header, footer, footnote, endnote, comment. This option sets the scope of the replacement procedure.
useHTMLExtended If true allows using HTML Extended tags. False as default.
wordStyles One may associate different Word styles to HTML classes, ids or tags.
Code samples

Example #1

A template can be a local file, a Base64 string, or a remote file.

Release notes
  • phpdocx 18.0:
    • new action.