Code View for Personalization Rules

Prev Next

Overview

Code View in the Personalization Builder lets you create personalization rules directly as code. It is intended for users who have at least basic knowledge of the expression language and some experience with queries.


  1. Navigate to Audience > Segmentation > Personalization.

  2. Create or edit a personalization.

  3. Click Code.


Key Behaviors and Limitations

  • Code-only rules: Some rules can only be created in code, for example conditions with advanced functions or special attribute types. See Functions.

  • Default structure: When you create a new personalization, the editor automatically creates a first InsertIf block without content.

  • Validation: Use Preview to check the rule before you save or reuse it. See Personalization Builder: Preview.

  • Reuse: You can save personalizations created in code and reuse them in other messages.

  • Switching back to the graphical interface: This is only possible if the code matches the structure that the graphical interface creates. Rules with code-only elements stay in Code View.

For the syntax of conditions and blocks, see Personalization Rules Syntax.


Examples

Inline placeholder

This example inserts the contact's first name into a sentence. You can place the placeholder anywhere in plain text or HTML.

Thanks for your order, <%${user['FirstName']}%>!

Greeting with fallback

This example adapts the greeting to the contact's title and last name. If the title or the last name is missing, a general greeting is used.

<%InsertIf expression="${(user['Title'] == '1') && (not empty user['LastName'])}" id="Greeting_M"%>Hello Mr. <%${user['LastName']}%>,<%/InsertIf%>
<%InsertElse expression="${(user['Title'] == '2') && (not empty user['LastName'])}" id="Greeting_F"%>Hello Ms. <%${user['LastName']}%>,<%/InsertElse%>
<%InsertElse id="Greeting_Default"%>Hello,<%/InsertElse%>

For more examples, see Personalization Rule Examples.