In code mode the whole email is one HTML document with Vascula template tags in it. Use it for full control of the layout, or for logic the visual editor doesn’t offer. The code is checked when you preview and save, and Tringify renders it for every email it sends.
Switch to code
Open the template in the email editor.
In the header, choose Code next to Visual.
Select Convert to code. The design becomes one HTML template, with its texts, values, links and visibility rules.
Review the checks: they list anything the conversion left out.
Edit the code. The preview beside it shows the result with sample data. Save when the checks pass.
The conversion leaves out Order items blocks (print the items with a {% for item in order.items %} loop), images without an address and barcodes made from a template value, each with a warning. The Order details block becomes {% order_details %} and the Tax details block {% tax_details %}.
The visual design is kept. To return to it, choose Visual and select Discard code changes: the code is discarded, and nothing you changed in code is copied back to the design.
Print values
Write a value in double braces, such as {{ order.number }} or {{ customer.first_name }}. Everything printed is escaped, so a customer’s note can’t add markup to your email. The values each email has are listed under Message values in the editor and in Use values in customer notification templates. A value the email doesn’t have stops the save; a value that is empty in a particular email prints nothing.
Pass a value through a filter with |. Besides Vascula’s standard filters for text, numbers, lists and links, emails have these:
Filter |
What it does |
Example |
|---|---|---|
money |
Writes an amount with its currency the way the customer’s language does. trim_zeros: true drops the decimals of a whole amount; isolate: true keeps the amount together in right-to-left text. |
{{ order.totals.total | money }} |
date |
Writes a date in the customer’s language and your store’s time zone: short, medium (the default), long, full or datetime, or a strftime format such as "%d/%m/%Y". |
{{ order.created_at | date: "long" }} |
format_number |
Writes a number with the separators of the customer’s language. |
{{ order.item_count | format_number }} |
pluralize |
Picks the singular or the plural word for a count, by the rules of the customer’s language. |
{{ order.item_count | pluralize: "item", "items" }} |
default |
Prints a fallback when the value is empty. |
{{ customer.first_name | default: "there" }} |
Conditions and loops
{% if %} … {% elsif %} … {% else %} … {% endif %} shows part of the email when its condition holds, {% unless %} … {% endunless %} when it doesn’t, and {% case %} … {% when %} … {% endcase %} picks one of several. Compare with ==, !=, <, >, <=, >= and contains, and combine conditions with and and or. Compare with blank to test for a missing or empty value, such as {% if order.customer_note != blank %}.
{% for item in order.items %} … {% endfor %} repeats for each item. limit:, offset: and reversed choose which items, an {% else %} inside the loop shows when the list is empty, forloop.index numbers the items, and {% break %} and {% continue %} leave the loop or skip an item. A list in an email holds at most 100 entries; when an order’s items were cut, order.items_truncated is true and order.line_count is the order’s full number of lines.
{% assign %} and {% capture %} keep a value for later; they can’t reuse the name of a data root such as order or customer. {# … #} and {% comment %} … {% endcomment %} are comments. {% render %} isn’t available in emails.
Order details and tax details
Two tags print a ready-made part of the email, in its default style, where you write them:
Tag |
Prints |
Available in |
|---|---|---|
{% order_details %} |
The shipping and billing addresses, the shipping method or pickup location, how the order is paid and the customer’s note, each under its heading in the customer’s language, two parts per row. A part the order has no value for is left out. |
Every email about an order |
{% tax_details %} |
The order’s tax lines or, in refund emails, the tax refunded. Use it once per email. |
Order Placed, Order Updated, Order Cancelled and Refunded, Order Cancelled and Partially Refunded, Payment Refunded and Payment Partially Refunded |
Use them in the email’s code only: the subject and preview text can’t contain them, and an email that doesn’t offer a tag can’t be saved with it. When an email that shows tax details doesn’t print {% tax_details %}, for example because the tag stands inside a condition that doesn’t hold, the tax details are added at the end of the email.
What an email can’t contain
Email programs don’t run scripts or forms, so code mode refuses to save them: