Wiki source code of Template engine for personalization of mass messagings
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | (% class="lead" %) | ||
| 2 | The template engine allows you to customize message content (email, SMS, push) in [[mass messagings>>doc:Main.Usage.Smart_Communications.Mass_messaging.WebHome]] and [[campaigns>>doc:Main.Smart_Communications.SMC_Use.Campaigns.WebHome]]. Each customer sees information in the message that is specifically relevant to them. | ||
| 3 | |||
| 4 | **Contents:** | ||
| 5 | |||
| 6 | {{toc depth="4" start="2"/}} | ||
| 7 | |||
| 8 | == Personalization == | ||
| 9 | |||
| 10 | Personalization enables messages to be tailored to each individual customer. [[Loymax Smart Communications>>doc:Main.Smart_Communications.SMC_Use.WebHome]] adapts message content and builds a personalized offer for each customer, optionally selecting the optimal send time. | ||
| 11 | |||
| 12 | **Example:** | ||
| 13 | Within the same product recommendation campaign: | ||
| 14 | |||
| 15 | * One customer receives a message (based on their purchase history) offering replacement razor blades, along with a promotional block stating that a “3 for the price of 2” offer is active at stores in their city. | ||
| 16 | * Another customer receives a message (based on their purchase history) offering a charger, along with a promo block announcing the opening of a new order pickup point in their city. | ||
| 17 | |||
| 18 | Loymax Smart Communications provides the following personalization tools: | ||
| 19 | |||
| 20 | * Template engine constructs; | ||
| 21 | * [[Product recommendations>>doc:Main.Loymax_AI.Commercial_recommendations.WebHome]]. | ||
| 22 | |||
| 23 | == Template engine == | ||
| 24 | |||
| 25 | The template engine includes: | ||
| 26 | |||
| 27 | * [[Variables>>doc:||anchor="H41F43544043543C43543D43D44B435432A0SmartCommunications"]] — data about the customer, their receipts, and products in those receipts. For example, a variable can be used to insert the customer’s name into a message; | ||
| 28 | * [[Macros>>doc:||anchor="H41C43043A44043E44144B"]] — functions that output information about promo codes, surveys, etc.; | ||
| 29 | * [[Control structures>>doc:||anchor="H42343F44043043243B44F44E44943843543A43E43D44144244044343A446438438"]] — loops, conditions, and filters. | ||
| 30 | |||
| 31 | Example of a variable used in a message: | ||
| 32 | |||
| 33 | (% class="box" %) | ||
| 34 | ((( | ||
| 35 | ##Good afternoon, ~{~{client.properties.full_name}}.## | ||
| 36 | ))) | ||
| 37 | |||
| 38 | When the message is sent, the variable is replaced with the actual value, for example: | ||
| 39 | |||
| 40 | (% class="box" %) | ||
| 41 | ((( | ||
| 42 | Good afternoon, Jane Doe. | ||
| 43 | ))) | ||
| 44 | |||
| 45 | == Variables in Smart Communications == | ||
| 46 | |||
| 47 | Variables allow you to insert dynamic data into message content (and, for emails, also into the subject line), including: | ||
| 48 | |||
| 49 | * From the [[customer profile>>doc:Main.Smart_Communications.SMC_Use.Customers.All_clients.WebHome||anchor="Profile"]]: | ||
| 50 | ** Customer attributes and metrics; | ||
| 51 | ** Links for [[subscription management>>doc:Main.Smart_Communications.SMC_Use.Mass_messaging.Subscription_synchronization.WebHome]]; | ||
| 52 | ** Attributes and contents from the most recent receipt and/or order; | ||
| 53 | ** Dates; | ||
| 54 | ** Any other custom attributes; | ||
| 55 | * Data about the customer’s receipts; | ||
| 56 | * Data about products in a receipt; | ||
| 57 | * Data about product categories. | ||
| 58 | |||
| 59 | Variables are categorized as: | ||
| 60 | |||
| 61 | * [[System variables>>doc:||anchor="H42143844144243543C43D44B43543F43544043543C43543D43D44B435"]] — used to access system fields; | ||
| 62 | * [[Custom variables>>doc:||anchor="H41F43E43B44C43743E43243044243543B44C44143A43843543F43544043543C43543D43D44B435"]] — used to access user-defined fields. More information about fields is available [[here>>doc:Main.Smart_Communications.SMC_Use.Settings_SC.Data_field.WebHome]]. | ||
| 63 | |||
| 64 | Variable syntax: | ||
| 65 | |||
| 66 | (% class="box" %) | ||
| 67 | ((( | ||
| 68 | ##~{~{variable_name}}## | ||
| 69 | ))) | ||
| 70 | |||
| 71 | === System variables === | ||
| 72 | |||
| 73 | The following system variables are available in Smart Communications: | ||
| 74 | |||
| 75 | (% class="table-bordered" %) | ||
| 76 | |=((( | ||
| 77 | Variable | ||
| 78 | )))|=((( | ||
| 79 | Purpose | ||
| 80 | ))) | ||
| 81 | |((( | ||
| 82 | ##~{~{client.properties.full_name}}## | ||
| 83 | )))|((( | ||
| 84 | Customer’s full name | ||
| 85 | ))) | ||
| 86 | |((( | ||
| 87 | ##~{~{client.properties.last_name}}## | ||
| 88 | )))|((( | ||
| 89 | Customer’s last name | ||
| 90 | ))) | ||
| 91 | |((( | ||
| 92 | ##~{~{client.properties.first_name}}## | ||
| 93 | )))|((( | ||
| 94 | Customer’s first name | ||
| 95 | ))) | ||
| 96 | |((( | ||
| 97 | ##~{~{client.properties.middle_name}}## | ||
| 98 | )))|((( | ||
| 99 | Customer’s middle name | ||
| 100 | ))) | ||
| 101 | |((( | ||
| 102 | ##~{~{client.properties.register_date}}## | ||
| 103 | )))|((( | ||
| 104 | Customer’s registration date | ||
| 105 | ))) | ||
| 106 | |((( | ||
| 107 | ##~{~{client.properties.city}}## | ||
| 108 | )))|((( | ||
| 109 | Customer’s city | ||
| 110 | ))) | ||
| 111 | |((( | ||
| 112 | ##~{~{client.properties.zip}}## | ||
| 113 | )))|((( | ||
| 114 | Customer’s ZIP code | ||
| 115 | ))) | ||
| 116 | |((( | ||
| 117 | ##~{~{client.properties.email}}## | ||
| 118 | )))|((( | ||
| 119 | Customer’s email | ||
| 120 | ))) | ||
| 121 | |((( | ||
| 122 | ##~{~{client.properties.password}}## | ||
| 123 | )))|((( | ||
| 124 | Customer’s password | ||
| 125 | ))) | ||
| 126 | |((( | ||
| 127 | ##~{~{client.properties.phone}}## | ||
| 128 | )))|((( | ||
| 129 | Customer’s phone number | ||
| 130 | ))) | ||
| 131 | |((( | ||
| 132 | ##~{~{client.properties.order_cnt}}## | ||
| 133 | )))|((( | ||
| 134 | Total number of customer receipts | ||
| 135 | ))) | ||
| 136 | |((( | ||
| 137 | ##~{~{client.properties.order_sum}}## | ||
| 138 | )))|((( | ||
| 139 | Total value of all customer receipts | ||
| 140 | ))) | ||
| 141 | |((( | ||
| 142 | ##~{~{client.orders.first.date}}## | ||
| 143 | )))|((( | ||
| 144 | Date of customer’s first receipt | ||
| 145 | ))) | ||
| 146 | |((( | ||
| 147 | ##~{~{client.orders.last.date}}## | ||
| 148 | )))|((( | ||
| 149 | Date of customer’s last receipt | ||
| 150 | ))) | ||
| 151 | |((( | ||
| 152 | ##~{~{client.orders.last.number}}## | ||
| 153 | )))|((( | ||
| 154 | Number of customer’s last receipt | ||
| 155 | ))) | ||
| 156 | |((( | ||
| 157 | ##~{~{client.properties.rating}}## | ||
| 158 | )))|((( | ||
| 159 | Customer scoring | ||
| 160 | ))) | ||
| 161 | |((( | ||
| 162 | ##~{~{client.links.profile}}## | ||
| 163 | )))|((( | ||
| 164 | Link to the customer’s profile in the Platform | ||
| 165 | ))) | ||
| 166 | |((( | ||
| 167 | ##~{~{client.links.unsubscribe}}## | ||
| 168 | )))|((( | ||
| 169 | Link to [[subscription management>>doc:Main.Smart_Communications.SMC_Use.Mass_messaging.Subscription_synchronization.WebHome]] | ||
| 170 | ))) | ||
| 171 | |((( | ||
| 172 | ##~{~{client.links.web_version}}## | ||
| 173 | )))|((( | ||
| 174 | Link to the web version of the email | ||
| 175 | ))) | ||
| 176 | |((( | ||
| 177 | ##~{~{client.properties.bonus_active}}## | ||
| 178 | )))|((( | ||
| 179 | Number of active bonus points | ||
| 180 | ))) | ||
| 181 | |((( | ||
| 182 | ##~{~{client.properties.bonus_expect_activate}}## | ||
| 183 | )))|((( | ||
| 184 | Number of bonus points awaiting activation | ||
| 185 | ))) | ||
| 186 | |((( | ||
| 187 | ##~{~{client.properties.bonus_expect_deactivate}}## | ||
| 188 | )))|((( | ||
| 189 | Number of bonus points awaiting deactivation | ||
| 190 | ))) | ||
| 191 | |((( | ||
| 192 | ##~{~{client.properties.bounce_expect_deactivate_date}}## | ||
| 193 | )))|((( | ||
| 194 | Bonus points deactivation date | ||
| 195 | ))) | ||
| 196 | |((( | ||
| 197 | ##~{~{client.properties.bonus_expect_deactivate_next}}## | ||
| 198 | )))|((( | ||
| 199 | Number of bonus points scheduled for deactivation soon | ||
| 200 | ))) | ||
| 201 | |((( | ||
| 202 | ##~{~{client.eventContext.<field_code>}}## | ||
| 203 | )))|((( | ||
| 204 | Data from the [[event context>>doc:Main.Smart_Communications.SMC_Use.Events_SmC.WebHome||anchor="HEventContext"]] | ||
| 205 | ))) | ||
| 206 | |((( | ||
| 207 | ##~{~{client.containers.webcart.items}}## | ||
| 208 | )))|((( | ||
| 209 | Shopping cart contents | ||
| 210 | ))) | ||
| 211 | |##~{~{client.properties.eorder_cnt}}##|Total number of customer orders | ||
| 212 | |##~{~{client.properties.eorder_sum}}##|Total value of all customer orders | ||
| 213 | |##~{~{client.eorders.first.date}}##|Date of customer’s first order | ||
| 214 | |##~{~{client.eorders.last.date}}##|Date of customer’s last order | ||
| 215 | |##~{~{client.eorders.first.number}}##|Number of customer’s first order | ||
| 216 | |##~{~{client.eorders.last.number}}##|Number of customer’s last order | ||
| 217 | |##~{~{client.eorders.first.<field_code>}}##|Value of a field in the customer’s first order | ||
| 218 | |##~{~{client.eorders.last.<field_code>}}##|Value of a field in the customer’s last order | ||
| 219 | |##~{~{client.eorders.first.items}}##|Contents of the first order | ||
| 220 | |##~{~{client.eorders.last.items}}##|Contents of the last order | ||
| 221 | |||
| 222 | === Custom variables === | ||
| 223 | |||
| 224 | Access to user-defined fields for **Customer/Receipt/Receipt Line/Product Category** is provided via their field code using the following syntax: ##~{~{client.properties.<field_code>}}##. For example: | ||
| 225 | |||
| 226 | (% class="box" %) | ||
| 227 | ((( | ||
| 228 | ##~{~{client.properties.eye_color}}## | ||
| 229 | ))) | ||
| 230 | |||
| 231 | You can find a field’s code in **Settings >** [[Fields>>doc:Main.Smart_Communications.SMC_Use.Settings_SC.Data_field.WebHome]] under the tab of the corresponding object (for example, client or product). For instance, the receipt attribute “Payment status” has the code “payment_status_name”. | ||
| 232 | |||
| 233 | {{lightbox image="Payment_status.png"/}} | ||
| 234 | |||
| 235 | To construct a variable, use the following formats: | ||
| 236 | |||
| 237 | * ##~{~{client.properties.<field_code>}}## — value of an attribute from the customer’s **profile**; | ||
| 238 | * ##~{~{client.orders.first.<field_code>}}## — value of an attribute from the customer’s **first receipt**; | ||
| 239 | * ##~{~{client.orders.last.<field_code>}}## — value of an attribute from the customer’s **last receipt**. | ||
| 240 | |||
| 241 | To output product attribute values from a [[cart abandonment>>doc:Main.Smart_Communications.SMC_Use.Campaigns.Abandoned_cart.WebHome]] scenario, first/last receipt, or product category, you must use [[(% class="wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink" %)loops>>doc:||anchor="H42643843A43B44B"]](%%). | ||
| 242 | |||
| 243 | === Default values === | ||
| 244 | |||
| 245 | For **string-type** attributes, you can define a default value. This value is used in the message if the attribute is empty. For example, you can address the customer by name, falling back to a default if the name is unknown: | ||
| 246 | |||
| 247 | (% class="box" %) | ||
| 248 | ((( | ||
| 249 | ##~{~{client.properties.full_name|default('Dear customer')}}## | ||
| 250 | ))) | ||
| 251 | |||
| 252 | == Macros == | ||
| 253 | |||
| 254 | Macros are small commands that execute scripted actions in the system. For example, the macro ##~{~{client.promocode('promo_code_group')}}## finds and returns a promo code from the specified group. | ||
| 255 | |||
| 256 | === System macros === | ||
| 257 | |||
| 258 | Smart Communications supports the following macros: | ||
| 259 | |||
| 260 | (% class="table-bordered" %) | ||
| 261 | |=((( | ||
| 262 | Macro | ||
| 263 | )))|=((( | ||
| 264 | Purpose | ||
| 265 | ))) | ||
| 266 | |((( | ||
| 267 | ##~{~{"now"|date('format')}}## | ||
| 268 | )))|((( | ||
| 269 | Current date | ||
| 270 | ))) | ||
| 271 | |((( | ||
| 272 | ##~{~{client.promocode('promo_code_group')}}## | ||
| 273 | )))|((( | ||
| 274 | Issue a promo code to the customer from the specified group | ||
| 275 | ))) | ||
| 276 | |((( | ||
| 277 | ##~{~{client.last_promocode('promo_code_group')}}## | ||
| 278 | )))|((( | ||
| 279 | Most recently issued promo code from the group | ||
| 280 | ))) | ||
| 281 | |((( | ||
| 282 | ##~{~{client.last_campaign_promocode('promo_code_group')}}## | ||
| 283 | )))|((( | ||
| 284 | Most recent promo code from the group issued within this campaign | ||
| 285 | ))) | ||
| 286 | |((( | ||
| 287 | ##~{~{client.template_constant('name')}}## | ||
| 288 | )))|((( | ||
| 289 | Regional constant | ||
| 290 | ))) | ||
| 291 | |((( | ||
| 292 | ##~{~{client.poll('POLL-<poll identifier>')}}## | ||
| 293 | )))|((( | ||
| 294 | Link to a poll | ||
| 295 | ))) | ||
| 296 | |((( | ||
| 297 | ##~{~{client.loyaltyCard.lastActive.number}}## | ||
| 298 | )))|((( | ||
| 299 | Information about the customer’s active loyalty card | ||
| 300 | ))) | ||
| 301 | |||
| 302 | === Date formats === | ||
| 303 | |||
| 304 | **Date-type** fields can be displayed in various formats. Use any combination of the following placeholders to define the format: | ||
| 305 | |||
| 306 | * Year: | ||
| 307 | ** y — 2 digits (e.g., 97, 20); | ||
| 308 | ** Y — 4 digits (e.g., 1997, 2020); | ||
| 309 | * m — month (01–12); | ||
| 310 | * d — day (01–31); | ||
| 311 | * h — hour; | ||
| 312 | * i — minute; | ||
| 313 | * s — second. | ||
| 314 | |||
| 315 | **Example 1. Displaying a date in a message** | ||
| 316 | |||
| 317 | With format 'Y-m-d', the date appears as '2020-10-20'. With format 'd.m.Y h:i', it appears as '20.10.2020 11:56'. | ||
| 318 | |||
| 319 | Example macro usage for **Thanking a customer for their latest order**: | ||
| 320 | |||
| 321 | (% class="box" %) | ||
| 322 | ((( | ||
| 323 | ##Thank you for your order placed on ~{~{client.orders.last.date|date('d.m.Y')}}!## | ||
| 324 | ))) | ||
| 325 | |||
| 326 | The customer receives a message like: | ||
| 327 | |||
| 328 | (% class="box" %) | ||
| 329 | ((( | ||
| 330 | Thank you for your order placed on 29.06.2020! | ||
| 331 | ))) | ||
| 332 | |||
| 333 | **Example 2. Displaying a date a few days after the current date** | ||
| 334 | |||
| 335 | To display a future date in the message, use this macro: | ||
| 336 | |||
| 337 | (% class="box" %) | ||
| 338 | ((( | ||
| 339 | ##~{~{"now"|date_modify('+1 day')|date('Y-m-d')}}## | ||
| 340 | ))) | ||
| 341 | |||
| 342 | The customer will see tomorrow’s date. | ||
| 343 | |||
| 344 | **Example 3. Displaying a date one month after the customer’s registration date** | ||
| 345 | |||
| 346 | Output a date that is +1 month from the customer’s registration date: | ||
| 347 | |||
| 348 | (% class="box" %) | ||
| 349 | ((( | ||
| 350 | ##~{~{client.properties.register_date|date_modify('+1 month')|date('Y-m-d')}}## | ||
| 351 | ))) | ||
| 352 | |||
| 353 | == Inserting a variable or macro into a message == | ||
| 354 | |||
| 355 | All message editors include a flag icon button. Clicking it reveals the list of available system variables and macros: | ||
| 356 | |||
| 357 | |(% style="border-color:white; text-align:center" %){{lightbox image="Variables.png"/}} | ||
| 358 | |||
| 359 | To insert a custom variable, you must type it manually. | ||
| 360 | |||
| 361 | == Preview == | ||
| 362 | |||
| 363 | |(% style="border-color:white; width:1115px" %)((( | ||
| 364 | To preview how the message will appear with variables and macros replaced by actual values, use the **Message preview** button. | ||
| 365 | )))|(% style="border-color:white; width:324px" %){{lightbox image="Preview_button.png"/}} | ||
| 366 | |(% style="border-color:white; width:1115px" %)((( | ||
| 367 | You can preview an email for a specific customer. In the **Customer** field, enter the customer’s last name/first name/phone number/email/local identifier (local_id). For unambiguous results, we recommend searching by phone number/email/local customer ID. | ||
| 368 | |||
| 369 | (% class="box infomessage" %) | ||
| 370 | ((( | ||
| 371 | The **Customer** search field is case-sensitive. Customer first and last names must be entered with an initial capital letter. | ||
| 372 | ))) | ||
| 373 | )))|(% style="border-color:white; width:324px" %){{lightbox image="Client_name.png"/}} | ||
| 374 | |||
| 375 | == Control structures == | ||
| 376 | |||
| 377 | Control structures enable the creation of more sophisticated templates using variables and macros. They include for-loops, conditional statements (if/elseif/else), and filters, and are enclosed in {% ... %} blocks. | ||
| 378 | |||
| 379 | === Variables === | ||
| 380 | |||
| 381 | To reuse the same expression multiple times in a message, define a variable. For example, define the variable ##webcart## for the shopping cart items array: | ||
| 382 | |||
| 383 | (% class="box" %) | ||
| 384 | ((( | ||
| 385 | ##{% set webcart = client.containers.webcart.items %}## | ||
| 386 | ))) | ||
| 387 | |||
| 388 | === Loops === | ||
| 389 | |||
| 390 | Use loops in the following scenarios: | ||
| 391 | |||
| 392 | * Output product attributes from the customer’s first/last receipt; | ||
| 393 | * Output product attributes from the cart; | ||
| 394 | * Output product category attributes; | ||
| 395 | * Display information for all active customer loyalty cards (when multiple exist). | ||
| 396 | |||
| 397 | For example, output the names of all products in the customer’s last receipt: | ||
| 398 | |||
| 399 | (% class="box" %) | ||
| 400 | ((( | ||
| 401 | ##{% for item in client.orders.last.items%} | ||
| 402 | ~{~{item.name}} | ||
| 403 | {% endfor %}## | ||
| 404 | ))) | ||
| 405 | |||
| 406 | Output name and color for all products in the cart: | ||
| 407 | |||
| 408 | (% class="box" %) | ||
| 409 | ##{% set webcart = client.containers.webcart.items %} | ||
| 410 | {% for item in webcart %} | ||
| 411 | ~{~{item.name}} | ||
| 412 | ~{~{item.color}} | ||
| 413 | {% endfor %}## | ||
| 414 | |||
| 415 | Output the category name for all products in the last order: | ||
| 416 | |||
| 417 | (% class="box" %) | ||
| 418 | ((( | ||
| 419 | ##{% for item in client.orders.last.items%} | ||
| 420 | ~{~{item.category.name}} | ||
| 421 | {% endfor %}## | ||
| 422 | ))) | ||
| 423 | |||
| 424 | Output information for all active customer cards: | ||
| 425 | |||
| 426 | (% class="box" %) | ||
| 427 | ((( | ||
| 428 | ##{% for card in client.loyaltyCard.items %} | ||
| 429 | ~{~{card.number}} | ||
| 430 | {% endfor %}## | ||
| 431 | ))) | ||
| 432 | |||
| 433 | === Conditions === | ||
| 434 | |||
| 435 | You can display data only when a specific condition is met. For example, issue a [[promo code>>doc:Main.Smart_Communications.SMC_Use.Promo_codes.WebHome]] only to customers from Birmingham: | ||
| 436 | |||
| 437 | (% class="box" %) | ||
| 438 | ((( | ||
| 439 | ##{% if client.properties.city == '##Birmingham##' %} | ||
| 440 | ~{~{client.promocode('promo_code_group')}} | ||
| 441 | {% endif %}## | ||
| 442 | ))) | ||
| 443 | |||
| 444 | Examples of condition syntax: | ||
| 445 | |||
| 446 | * {% if client.properties.city == 'Birmingham' %} — if the customer is from Birmingham; | ||
| 447 | * {% if client.properties.city %} — if the customer’s city is specified; | ||
| 448 | * {% if not client.properties.city %} — if the customer’s city is not specified; | ||
| 449 | * {% if client.properties.city == 'Birmingham' OR client.properties.city == 'Manchester' %} — if the customer is from Birmingham or Manchester; | ||
| 450 | * {% if client.properties.city == 'Birmingham' AND client.properties.first_name == 'Maria' %} — if the customer is from Birmingham and their name is Maria. | ||
| 451 | |||
| 452 | === Filters === | ||
| 453 | |||
| 454 | The following filters are available for arrays: | ||
| 455 | |||
| 456 | * sortArray — sorts an array by attribute values: | ||
| 457 | ** sortArray('date', true) — descending date order; | ||
| 458 | ** sortArray('date', false) — ascending date order (you can sort by other attributes as well); | ||
| 459 | * get — limits the number of elements returned: | ||
| 460 | ** get(10) — returns the first 10 array elements; | ||
| 461 | * date_diff('date') — calculates the number of days between two dates. For example, output the number of days from **2020-11-11** to today: | ||
| 462 | |||
| 463 | (% class="box" %) | ||
| 464 | ((( | ||
| 465 | ##~{~{"now"|date('Y-m-d')|date_diff('2020-11-11')}}## | ||
| 466 | ))) | ||
| 467 | |||
| 468 | **Outputting cart data** | ||
| 469 | |||
| 470 | Example using filters: output the name, image, and price for the first 10 products added to the cart. | ||
| 471 | |||
| 472 | (% class="box" %) | ||
| 473 | ((( | ||
| 474 | ##{% set webcart = client.containers.webcart.items|sortArray('date', false)|get(10) %} | ||
| 475 | {% for item in webcart %} | ||
| 476 | ~{~{item.name}} | ||
| 477 | ~{~{item.image_url}} | ||
| 478 | ~{~{item.price}} | ||
| 479 | {% endfor %}## | ||
| 480 | ))) | ||
| 481 | |||
| 482 | To make the product name a clickable link, use an <a> tag with an href attribute: | ||
| 483 | |||
| 484 | (% class="box" %) | ||
| 485 | ((( | ||
| 486 | ##<a href="~{~{item.product_url}}">~{~{item.name}}</a>## | ||
| 487 | ))) | ||
| 488 | |||
| 489 | == Adding data from data marts == | ||
| 490 | |||
| 491 | Loymax Smart Communications allows you to insert values from [[data marts>>doc:Main.Smart_Communications.SMC_Use.Settings_SC.Data_field.WebHome||anchor="H41243844244043843D44B"]] into message content. For “one-to-one” marts, use the following syntax: | ||
| 492 | |||
| 493 | (% class="box" %) | ||
| 494 | ((( | ||
| 495 | ##~{~{client.marts.<mart_code>.<field_code>}}## | ||
| 496 | ))) | ||
| 497 | |||
| 498 | For multi-marts (collections of objects), use a loop: | ||
| 499 | |||
| 500 | (% class="box" %) | ||
| 501 | ((( | ||
| 502 | ##{% set items = client.multimarts.<mart_code>.items %} | ||
| 503 | {% for item in items %} | ||
| 504 | ~{~{item.<field_code_1>}} | ||
| 505 | ~{~{item.<field_code_2>}} | ||
| 506 | ~{~{item.<field_code_3>}} | ||
| 507 | {% endfor %}## | ||
| 508 | ))) | ||
| 509 | |||
| 510 | == Using trigger context data == | ||
| 511 | |||
| 512 | When a [[trigger>>doc:Main.Smart_Communications.SMC_Use.Campaigns.Triggers.WebHome]] fires, the trigger context stores information about the object or collection of objects that caused the trigger. Depending on the trigger type, this could be a product, order, category, etc. The context is always tied to a specific customer and can be used to personalize communications. | ||
| 513 | |||
| 514 | In campaign messages, you can use values from the [[fields>>doc:Main.Smart_Communications.SMC_Use.Settings_SC.Data_field.WebHome]] of the object in the trigger context. The data structure matches the object’s data model and includes all fields configured for that object type. | ||
| 515 | |||
| 516 | Every trigger context includes a ##client## object. Using this object, you can access any field from the [[customer profile>>doc:Main.Smart_Communications.SMC_Use.Customers.All_clients.WebHome||anchor="H41F44043E44443843B44C43A43B43843543D442430"]], whether system or custom. Use the following syntax: ##~{~{trigger.client.properties.<field_code>}}## | ||
| 517 | |||
| 518 | Some triggers pass additional objects besides ##client##. See the table below. | ||
| 519 | |||
| 520 | (% class="table-bordered" %) | ||
| 521 | |=Triggers|=Objects in context|=Notes | ||
| 522 | |((( | ||
| 523 | * [[Days since receipt>>doc:Main.Smart_Communications.SMC_Use.Campaigns.Triggers.WebHome||anchor="HDayssincereceipt"]] | ||
| 524 | * [[Date come for receipt>>doc:Main.Smart_Communications.SMC_Use.Campaigns.Triggers.WebHome||anchor="HDatecomeforcheque"]] | ||
| 525 | * [[Receipt issued>>doc:Main.Smart_Communications.SMC_Use.Campaigns.Triggers.WebHome||anchor="HChequeissued"]] | ||
| 526 | )))|((( | ||
| 527 | * ##client## (Customer) | ||
| 528 | * ##order## (Receipt) | ||
| 529 | )))|((( | ||
| 530 | (% id="cke_bm_68121S" style="display:none" %) (%%)To access receipt fields, use: ##~{~{trigger.order.<receipt_field_code>}}## | ||
| 531 | |||
| 532 | To iterate over all receipt lines, use a loop: | ||
| 533 | |||
| 534 | {{code}} | ||
| 535 | {% for item in trigger.order.items %} | ||
| 536 | {{item.<receipt_line_field_code>}} | ||
| 537 | {% endfor %} | ||
| 538 | {{/code}} | ||
| 539 | |||
| 540 | Receipt lines also include a ##category## field populated with data from the product’s category. Access category fields using: ##~{~{item.category.<category_field_code>}}## | ||
| 541 | ))) | ||
| 542 | |((( | ||
| 543 | * [[Days since order>>doc:Main.Smart_Communications.SMC_Use.Campaigns.Triggers.WebHome||anchor="HDayssinceorder"]] | ||
| 544 | * [[Item ordered>>doc:Main.Smart_Communications.SMC_Use.Campaigns.Triggers.WebHome||anchor="HItemordered"]] | ||
| 545 | * [[Item from specific category ordered>>doc:Main.Smart_Communications.SMC_Use.Campaigns.Triggers.WebHome||anchor="HItemfromspecificcategoryordered"]] | ||
| 546 | * [[Order status changed>>doc:Main.Smart_Communications.SMC_Use.Campaigns.Triggers.WebHome||anchor="HOrderstatuschanged"]] | ||
| 547 | * [[Date come for order>>doc:Main.Smart_Communications.SMC_Use.Campaigns.Triggers.WebHome||anchor="HDatecomefororder"]] | ||
| 548 | * [[Order created>>doc:Main.Smart_Communications.SMC_Use.Campaigns.Triggers.WebHome||anchor="HOrdercreated"]] | ||
| 549 | )))|((( | ||
| 550 | * ##client## (Customer) | ||
| 551 | * ##eorder## (Order) | ||
| 552 | )))|((( | ||
| 553 | (% id="cke_bm_74915S" style="display:none" %) (%%)To access order fields, use: ##~{~{trigger.eorder.<order_field_code>}}## | ||
| 554 | |||
| 555 | To iterate over all order lines, use a loop: | ||
| 556 | |||
| 557 | {{code}} | ||
| 558 | {% for item in trigger.eorder.items %} | ||
| 559 | {{item.<order_line_field_code>}} | ||
| 560 | {% endfor %} | ||
| 561 | {{/code}} | ||
| 562 | |||
| 563 | Order lines also include a ##category## field. Access category fields using: ##~{~{item.category.<category_field_code>}}## | ||
| 564 | ))) | ||
| 565 | |[[Added product to container>>doc:Main.Smart_Communications.SMC_Use.Campaigns.Triggers.WebHome||anchor="HAddedaproducttothecontainer"]]|((( | ||
| 566 | * ##client## (Customer) | ||
| 567 | * ##product## (Product) | ||
| 568 | )))|Use this syntax to access product fields: ##~{~{trigger.product.<product_field_code>}}## | ||
| 569 | |((( | ||
| 570 | * [[Price of viewed product changed>>doc:Main.Smart_Communications.SMC_Use.Campaigns.Triggers.WebHome||anchor="HThepriceoftheviewedproducthaschanged"]] | ||
| 571 | * [[Product price changed>>doc:Main.Smart_Communications.SMC_Use.Campaigns.Triggers.WebHome||anchor="HProductpricehaschanged"]] | ||
| 572 | )))|((( | ||
| 573 | * ##client## (Customer) | ||
| 574 | * ##products## (collection of Product objects) | ||
| 575 | )))|((( | ||
| 576 | To iterate over all products in the collection, use a loop: | ||
| 577 | |||
| 578 | {{code}} | ||
| 579 | {% for product in trigger.products %} | ||
| 580 | {{product.<product_field_code>}} | ||
| 581 | {% endfor %} | ||
| 582 | {{/code}} | ||
| 583 | ))) | ||
| 584 | |[[Lost view of category>>doc:Main.Smart_Communications.SMC_Use.Campaigns.Triggers.WebHome||anchor="HLostviewofcategory"]]|((( | ||
| 585 | * ##client## (Customer) | ||
| 586 | * ##category## (Product category) | ||
| 587 | )))|((( | ||
| 588 | Because this trigger processes events from the last 48 hours, many **Category view** (##view_category##) events may occur. Only two categories are stored in the trigger context: the most recently viewed and the most frequently viewed. | ||
| 589 | |||
| 590 | To reference the most recently viewed category, use: ##~{~{trigger.last_category.<category_field_code>}}## | ||
| 591 | |||
| 592 | To reference the most frequently viewed category, use: ##~{~{trigger.frequent_category.<category_field_code>}}## | ||
| 593 | ))) | ||
| 594 | |||
| 595 | {{showhide showmessage="Example: accessing the ~"Order placed~" trigger context" hidemessage="Hide example"}} | ||
| 596 | |(% style="width:50%" %)((( | ||
| 597 | **Code:** | ||
| 598 | |||
| 599 | (% class="box" %) | ||
| 600 | ((( | ||
| 601 | ##~{~{trigger.client.properties.full_name}}##, | ||
| 602 | ##~{~{trigger.eorder.date}}## you placed order ##~{~{trigger.eorder.number}}## for ##~{~{trigger.eorder.items_sum}}## with delivery to ##~{~{trigger.eorder.delivery_city}}.## | ||
| 603 | |||
| 604 | Order contents: | ||
| 605 | |||
| 606 | ##{% for item in trigger.eorder.items %}## | ||
| 607 | Product name: ##~{~{item.name}}## | ||
| 608 | Quantity: ##~{~{item.cnt}}## | ||
| 609 | Price: ##~{~{item.price}}## | ||
| 610 | Discount: ##~{~{item.discount}}## | ||
| 611 | Item total: ##~{~{item.cnt}} x (~{~{item.price}} - ~{~{item.discount}}) = ~{~{item.sum}}## | ||
| 612 | {% endfor %}} | ||
| 613 | ))) | ||
| 614 | )))|(% style="width:50%" %)((( | ||
| 615 | **Rendered result:** | ||
| 616 | |||
| 617 | Konstantin Konstantinovsky, | ||
| 618 | 01.01.2025 you placed order EO-12345 for 5100 with delivery to Saint Petersburg. | ||
| 619 | |||
| 620 | Order contents: | ||
| 621 | |||
| 622 | Product name: Garden watering can | ||
| 623 | Quantity: 2 | ||
| 624 | Price: 1500 | ||
| 625 | Discount: 100 | ||
| 626 | Item total: 2 x (1500 - 100) = 2800 | ||
| 627 | |||
| 628 | Product name: Spade | ||
| 629 | Quantity: 1 | ||
| 630 | Price: 2500 | ||
| 631 | Discount: 200 | ||
| 632 | Item total: 1 x (2500 - 200) = 2300 | ||
| 633 | ))) | ||
| 634 | {{/showhide}} | ||
| 635 | |||
| 636 | (% class="box" %) | ||
| 637 | ((( | ||
| 638 | **See also:** | ||
| 639 | |||
| 640 | * [[Campaigns>>doc:Main.Smart_Communications.SMC_Use.Campaigns.WebHome]] | ||
| 641 | * [[Triggers>>doc:Main.Smart_Communications.SMC_Use.Campaigns.Triggers.WebHome]] | ||
| 642 | * [[Fields>>doc:Main.Smart_Communications.SMC_Use.Settings_SC.Data_field.WebHome]] | ||
| 643 | ))) |