Style Functions
Style functions set the InDesign style of text or of a design object, with optional font and color overrides. The style is applied only where InDesign places the text: print, proof and preview. In uCreate XLIM documents, only the text is placed. In other outputs (HTML, email, Text File content objects and flat data such as CSVX), the TextWithStyle value is output as is, so its style codes appear as text. Use TextWithStyle only in content objects placed in InDesign documents.
Note: Style and TextWithStyle are reserved names. A custom function in the plan with either name replaces the built-in function and causes a validation warning. Rename it.
Style function
The Style function names an InDesign character style or object style, optionally with font and color overrides. Use it as the rule of a Style content object.
Syntax
Style(baseStyle, fontFamily, fontStyle, size, fillColor)
| Parameter | Description |
|---|---|
| baseStyle | Optional. The name of an InDesign character style or object style in the document. The name must match the style exactly. "[Default]" applies no style, so the text keeps the formatting it has in the document. |
| fontFamily | Optional. A font family that overrides the style's font, for example "Arial". |
| fontStyle | Optional. A font style of the font family, for example "Bold". |
| size | Optional. The font size in points, for example "14". |
| fillColor | Optional. The name of a swatch in the document, for example "Red", or a CMYK value written "[c,m,y,k]", where each value is from 0 to 1, for example "[0,1,1,0]". The color applies to the contents of the frame, not to the frame itself. |
The parameters must be in this order. An empty parameter ("") means no override, and parameters at the end can be left out.
Examples
-
Apply a character style:
Style("Title")
-
Apply a character style, overriding only its color:
Style("Title", "", "", "", "Red")
-
Apply a different style to premium-tier customers:
if(|->[Category] == "PLATINUM") Style("PremiumPrice") else Style("RegularPrice")
TextWithStyle function
The TextWithStyle function returns text together with the style it is set in. Use it as the rule of a Text with Style content object.
Syntax
TextWithStyle(text, baseStyle, fontFamily, fontStyle, size, fillColor)
| Parameter | Description |
|---|---|
| text | Required. The text to show: a constant, an input data field, a variable or any other expression. |
| baseStyle, fontFamily, fontStyle, size, fillColor | Optional. The same as for the Style function. |
In a Text with Style rule, each value the rule returns must be a whole TextWithStyle call, not joined to other text. For example, "Dear " & TextWithStyle(|->[FirstName], "Title") is refused by the rule editor, and causes a warning in production.
Examples
-
Show fixed text with no style:
TextWithStyle("Hello World", "[Default]")
-
Show the recipient's first name in a character style, with font and color overrides:
TextWithStyle(|->[FirstName], "Title", "Arial", "Bold", "14", "Red")
-
Show the first name in a different style for premium-tier customers:
if(|->[Category] == "PLATINUM") TextWithStyle(|->[FirstName], "PremiumPrice") else TextWithStyle(|->[FirstName], "RegularPrice")
More topics
Define a rule for a Style or Text with Style content object
String Functions - Functions for text manipulation
uImage Functions - Functions for personalized images