{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-docs/email-api/template_language/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["code-snippet"]},"type":"markdown"},"seo":{"title":"Template Language Reference","siteUrl":"https://dev.mailjet.com/","projectTitle":"Mailjet Developer Documentation","description":"Full syntax reference for Mailjet template language: delimitators, arithmetic and logical operators, var/data/mj namespaces, functions, and control structures.","image":"https://dev.mailjet.com/og-image.png","lang":"en-US","keywords":["Mailjet API","Email API","Content API","SMTP Relay","transactional email","email delivery","Send API","email templates","developer documentation"],"meta":[{"name":"og:type","content":"website"},{"name":"og:site_name","content":"Mailjet Developer Documentation"},{"name":"twitter:card","content":"summary_large_image"},{"name":"robots","content":"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1"},{"name":"googlebot","content":"index, follow, max-snippet:-1, max-image-preview:large"}],"jsonLd":{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://dev.mailjet.com/#organization","name":"Mailjet","alternateName":"Sinch Mailjet","url":"https://www.mailjet.com","logo":"https://assets.mailjet.com/lib/images/mailjetLogo/mj_logo_with_text_color.png","parentOrganization":{"@type":"Organization","name":"Sinch","url":"https://www.sinch.com"}},{"@type":"WebSite","@id":"https://dev.mailjet.com/#website","name":"Mailjet Developer Documentation","description":"Official developer documentation for the Mailjet Email API, Content API and SMTP Relay.","url":"https://dev.mailjet.com/","inLanguage":"en-US","publisher":{"@id":"https://dev.mailjet.com/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://dev.mailjet.com/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]},"llmstxt":{"hide":false,"title":"Mailjet Developer Documentation","description":"Developer documentation for the Mailjet Email API, Content API and SMTP Relay - guides, API references and code samples for sending, templating and tracking email at scale.","details":{"content":"Mailjet (part of Sinch) provides APIs for sending and managing email.\n\nThis documentation covers four main areas:\n\n- **Email API** - the Send API (v3 and v3.1) for transactional and marketing email,\n  plus contact management, segmentation, campaigns, statistics, webhooks, the Parse API\n  and the Mailjet Templating Language.\n- **Content API** - programmatic management of email templates, template contents,\n  images, labels and authentication tokens (v1).\n- **SMTP Relay** - sending through Mailjet's SMTP servers, including custom headers.\n- **API Reference** - the complete, generated reference for every endpoint, built directly\n  from the OpenAPI specifications.\n\nBase URL for all REST APIs: `https://api.mailjet.com`.\nAuthentication uses HTTP Basic auth with an API key and secret key.\n\n## Machine-readable entry points\n\nPrefer these when you need the API surface in as few requests as possible:\n\n- `/openapi/openapi-mailjet.md` - the **complete** Email API reference (every endpoint,\n  grouped by resource) as a single Markdown document.\n- `/openapi/openapi-passport.md` - the **complete** Content API reference as a single\n  Markdown document.\n- `/_bundle/openapi/openapi-mailjet.yaml` - the raw, fully bundled OpenAPI 3 description\n  of the Email API.\n- `/_bundle/openapi/openapi-passport.yaml` - the raw, fully bundled OpenAPI 3 description\n  of the Content API.\n- `/sitemap.xml` - every indexable URL on this site.\n\nEvery page on this site is also available as clean Markdown by appending `.md` to its URL."},"sections":[{"title":"Email API","description":"Sending, contacts, campaigns, statistics, webhooks and templating.","includeFiles":["docs/email-api/**/*.md"],"excludeFiles":[]},{"title":"Content API","description":"Manage templates, template contents, images, labels and tokens.","includeFiles":["docs/content-api/**/*.md","docs/content-api.md"],"excludeFiles":[]},{"title":"SMTP Relay","description":"Send email through Mailjet's SMTP servers.","includeFiles":["docs/smtp-relay/**/*.md"],"excludeFiles":[]},{"title":"API Reference","description":"Complete generated reference for every Mailjet API endpoint.","includeFiles":["openapi/openapi-mailjet.yaml","openapi/openapi-passport.yaml","docs/api-reference/**/*.md"],"excludeFiles":[]},{"title":"Migrating from Mandrill","description":"Guides for switching from Mandrill to Mailjet.","includeFiles":["docs/mandrill/**/*.md"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"template-language-reference","__idx":0},"children":["Template Language Reference"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This page describes the logic of the Mailjet's template language and the syntax, variables, functions and statements available for the creation of a dynamic template."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"delimitators","__idx":1},"children":["Delimitators"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The template language elements need to be wrapped between the following delimitators:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["{{ ... }}"]}," for expressions that you would like to print in the template output"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["{% ... %}"]}," for statements (conditions and loops)"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"operators","__idx":2},"children":["Operators"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"arithmetic-operators","__idx":3},"children":["Arithmetic Operators:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["+"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["-"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["*"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["/"]}," : float division"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["div"]}," : integer division , Format: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["( X div Y )"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mod"]}," :remainder of division, Format: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["( X mod Y )"]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"comparison-operators","__idx":4},"children":["Comparison Operators:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":[">"]}," : strict superior"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["<"]}," : strict inferior"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":[">="]}," : superior"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["<="]}," : inferior"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["=, ==, ==="]}," : equals"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["!=, <>"]}," : not equals"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"logical-operators","__idx":5},"children":["Logical Operators"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["and"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["or"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xor"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["not"]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"variables","__idx":6},"children":["Variables"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Four sources of variables (or namespaces) are on offer in the template language. They can be used for simple insertion with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["{{ ... }}"]}," or with operators, functions and control structures."]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Vars ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["(var)"]}," : non-persistent information, sent with the message"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Contact properties - ContactData ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["(data)"]}," : information related to the contact, already stored in Mailjet system"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Predefined static variables ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["(mj)"]}," : allowing you to easily access specific information related to the contact, sender, template and others"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Segmentation `(segmentation) : leveraging the existing segmentation formulas you created for marketing purposes."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"vars-and-custom-vars","__idx":7},"children":["Vars and Custom Vars"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You can use the Mailjet Send API vars and custom vars (Vars property) to push contact specific information to be inserted in the template. This information will not be persistent in Mailjet system and will only be used for the current Send API call."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You can then use the syntax ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["{{var:namevar:defaultvalue}} "]},"to print the value of the property in your template."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["In order to have the template language interpreted, you must provide ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Mj-TemplateLanguage"]}," property in the payload to the Send API and set it to ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["true"]},"."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Mailjet templating language support multidimensional json structure in the vars and custom vars:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"./code_snippets/vars.html","language":"html","title":"vars","header":{"title":"vars","controls":{"copy":{}}},"lang":"html","source":"{\n...\n\"Vars\":{\n\t\"x\":{\n\t\t\"test\": 2,\n\t\t\"test2\": {\n\t\t\t\"test3\": \"Hello\"\n\t\t}\n\t}\n}\n...\n}"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"template","__idx":8},"children":["Template"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"{{ var:x.test }} {{ var:x.test2.test3 }}\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"html-result","__idx":9},"children":["HTML Result"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"2 Hello\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"contact-properties","__idx":10},"children":["Contact Properties"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["In your templates, you can use the contact properties. You can then use the syntax ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["{{data:namedata:defaultvalue}}"]}," to print the value in your template."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"predefined-static-variables","__idx":11},"children":["Predefined static variables"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["These variables are useful to access information related to the sender, the recipient and the template. They also allow you to access URLs related to your message."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"mjcontact","__idx":12},"children":["mj:contact"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["mj:contact represents the recipient of the current message (related to /contact resource of Mailjet API and recipient defined in the Send API call)."]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mj:contact.ID"]}," : Mailjet Contact ID"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mj:contact.email"]}," : Email address (local_part@domain)"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mj:contact.local_part"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mj:contact.domain"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mj:contact.name : Name of the contact"]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"mjsender","__idx":13},"children":["mj:sender"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["mj:sender represents the sender of the current message (related to /sender resource of Mailjet API and recipient defined in the Send API call)."]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mj:sender.ID"]}," : Mailjet Sender ID"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mj:sender.email"]}," : Email address (local_part@domain)"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mj:sender.local_part"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mj:sender.domain"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mj:sender.name"]}," : Name of the sender"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"mjtemplate","__idx":14},"children":["mj:template"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["mj:template represents the template used to generate this message (related to /template resource of Mailjet API)."]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mj:template.ID"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mj:template.name"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mj:template.copyright"]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"more","__idx":15},"children":["More"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mj:unsub_link"]},": the unsubscription link in english (EN)"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mj:unsub_link_$lang"]},": the unsubscription link in the specified language (ISO-639-1 formatted)"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mj:share_twitter"]},": the Twitter link to share the online version of the newsletter"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mj:share_google"]},": the Google+ link to share the online version of the newsletter"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mj:share_facebook"]},": the Facebook link to share the online version of the newsletter"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mj:share_linkedin"]},": the LinkedIn link to share the online version of the newsletter"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"segmentation","__idx":16},"children":["Segmentation"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The segmentation formulas, that you create with /contactfilter, as described in the Segmentation section, can be used in the template. It helps to easily mutualise your Marketing Campaigns logic and transactional template logic."]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["You can use either the Name or ID of the /contactfilter in the syntax ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["{{segment:nameORid}}"]}," to print the value in your template."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["The segmentation variables are also available in condition statement but can't be used and combined with logical operators (AND, OR, NOT, etc)."]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"./code_snippets/segmentation.html","language":"html","title":"segmentation","header":{"title":"segmentation","controls":{"copy":{}}},"lang":"html","source":"<html>\n  <body>\n    {% if segment:nameSegment %}\n    <h1>Recipient {{mj:contact.email}} matches segment nameSegment</h1>\n    {% endif %}\n  </body>\n</html>"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"functions","__idx":17},"children":["Functions"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"behavior-of-the-contact","__idx":18},"children":["Behavior of the contact"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["HasOpenedSince(number_of_days)"]}," : return true if the contact has opened a message in the last number of days."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["HasClickedSince(number_of_days)"]}," : return true if the contact has clicked on a link in a message in the last number of days."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"string-modification","__idx":19},"children":["String modification"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Upper(string)"]}," : Uppercase the string"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Lower(string)"]}," : Lowercase the string"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Capitalize(string)"]}," : Capitalize the first letter of the string"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"mathmatical-function","__idx":20},"children":["Mathmatical function"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Round(value, precision)"]}," : round a value at precision decimals"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Int(value)"]}," : Return the integer part of a number"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"formatting-functions","__idx":21},"children":["Formatting functions"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["FormatNumberLocale(format, number, locale)"]}," : allows you to specify the format of a float"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Format : a string parameter which accepts the following symbols: 0 (zero)"]}," : represents a forced digit. This means that whether or not the digit is relevant to the value, it will be displayed # (hash) : represents an optional digit , (comma) : represents the thousands separator in the number being displayed . (dot) : represents the location of the decimal point in the number being displayed"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Number"]}," : represents the numerical value you would like to format."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["`Locale : a string parameter which defines the decimal point and the thousands separator."]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"Possible use cases: FormatNumber(\"#,###.00\", 1000, \"fr_FR\"): 1 000,00\nFormatNumber (\"0.##\", 0.666666, \"en_GB\"): 0.67\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["FormatNumber(format,number)"]}," : replicates the behavior of ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["FormatNumberLocale"]},", but with default locale set to ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["“en_US”"]},", defining the decimal point as the . chararcter and the thousand separator as the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":[","]}," character."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"Possible use cases: FormatNumber(\"#,###.00\", 1000): 1,000.00 FormatNumber(\".00\",\n0.99) => .99\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"encoding-and-formatting","__idx":22},"children":["Encoding and Formatting"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["UrlEncode(string)"]}," : Encode a string for use in a URL"," ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Escape(html)"]}," : Encode html to be displayed as code in the message"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"conditional-statements","__idx":23},"children":["Conditional Statements"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["if"]},",",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["else"]},",",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["elseif"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["endif"]}," allow you to insert conditional display of information in your template."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["if"]}," statements can be nested inside one another."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"./code_snippets/conditional_1.html","language":"html","title":"conditional statements","header":{"title":"conditional statements","controls":{"copy":{}}},"lang":"html","source":"<html>\n  <body>\n    {% if data:age > 45 %}\n    <ul>\n      <li>{{data:age}}</li>\n    </ul>\n    {% endif %}\n  </body>\n</html>"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"./code_snippets/conditional_2.html","language":"html","title":"conditional statements HTML results","header":{"title":"conditional statements HTML results","controls":{"copy":{}}},"lang":"html","source":"<html>\n  <body>\n    <ul>\n      <li>46</li>\n    </ul>\n  </body>\n</html>\n\nor\n\n<html>\n  <body></body>\n</html>"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"./code_snippets/multiple_branches.html","language":"html","title":"Multiple branches of `if statement`","header":{"title":"Multiple branches of `if statement`","controls":{"copy":{}}},"lang":"html","source":"{% if data:age >= 21 %} You can code, drink and vote! {% elseif data:age >= 18\n%} You can't drink but hey, you still can code and vote! {% else %} A few more\nyears to wait !!! {% endif %}"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The conditional statement allows the usage of a default value for your variables. This can be helpful if you are not always passing all the variables in your Send API call."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You can specify a default value with the usual format ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["var:name:default_value"]},"."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The behavior of the conditional statement will be as follow:"," ","(Table)"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"set-function","__idx":24},"children":["Set function"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You can use the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["set"]}," function to assign value to a variable, directly in the template. You can then print the value or use it in conditional statements."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You can set values as string, integer, float, boolean, variable or contact data."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"b","attributes":{},"children":["Printing value"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"./code_snippets/print_value1.html","language":"html","title":"","header":{"title":"","controls":{"copy":{}}},"lang":"html","source":"Hello {% set yo-yo = \"Benjamin\" %} {{ yo-yo }} !"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"./code_snippets/print_value2.html","language":"html","title":"","header":{"title":"","controls":{"copy":{}}},"lang":"html","source":"Hello Benjamin!"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"b","attributes":{},"children":["You can change the value of the variable anytime."]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"./code_snippets/change_var_value1.html","language":"html","title":"","header":{"title":"","controls":{"copy":{}}},"lang":"html","source":"Hello {% set yo-yo = \"Benjamin\" %} {{ yo-yo }},\nhow is {% set yo-yo = \"Jane\" %} {{ yo-yo }} ?"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"./code_snippets/change_var_value2.html","language":"html","title":"","header":{"title":"","controls":{"copy":{}}},"lang":"html","source":"Hello Benjamin, how is Jane ?"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"b","attributes":{},"children":["In conditional statement"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"./code_snippets/con_statement6.html","language":"html","title":"","header":{"title":"","controls":{"copy":{}}},"lang":"html","source":"Hello {% set yo-yo = 1 %}{% if yo-yo >= 1 %} Benjamin {% endif %} !"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"./code_snippets/con_statement7.html","language":"html","title":"","header":{"title":"","controls":{"copy":{}}},"lang":"html","source":"Hello Benjamin!"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"loop-statements","__idx":25},"children":["Loop Statements"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["for in"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["endfor"]}," allows to insert an iteration on a JSON object or array in your template."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The syntax is:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"./code_snippets/loop_statement1.html","language":"html","title":"","header":{"title":"","controls":{"copy":{}}},"lang":"html","source":"{% for variable-name in name_space:json-source %}\n  html or/and nested statement\n{% endfor %}"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["On each iteration, the value of the current element from ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["name_space:json-source"]}," is assigned to ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["variable-name"]},"."," ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["variable-name"]}," can be used for display ( i.e. {{ variable-name }} ) or inside a nested statement."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"b","attributes":{},"children":["JSON payload"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"json","header":{"controls":{"copy":{}}},"source":"{\n\n\"Vars\":{\"x\":[1, true, \"Pilot\"]}\n\n}\n","lang":"json"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["or"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"json","header":{"controls":{"copy":{}}},"source":"{\n\n\"Vars\":{\"x\":{\"test1\":1, \"test2\":true,\"test3\":\"Pilot\"}}\n\n}\n","lang":"json"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"b","attributes":{},"children":["Template"]}," ","The syntax is:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"./code_snippets/loop_template.html","language":"html","title":"Template","header":{"title":"Template","controls":{"copy":{}}},"lang":"html","source":"<html>\n  <body>\n    <ul>\n      {% for value in var:x %}\n      <li>{{value}}</li>\n      {% endfor %}\n    </ul>\n  </body>\n</html>"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"b","attributes":{},"children":["Template"]}," ","The syntax is:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"./code_snippets/loop_statement.html","language":"html","title":"HTML result","header":{"title":"HTML result","controls":{"copy":{}}},"lang":"html","source":"<html>\n  <body>\n    <ul>\n      <li>1</li>\n      <li>true</li>\n      <li>Pilot</li>\n    </ul>\n  </body>\n</html>"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"multidimensional-array","__idx":26},"children":["Multidimensional array"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["for"]}," statements can be nested inside one another. It allows to intersect multiple arrays or objects and manage multidimensional array."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"json","header":{"controls":{"copy":{}}},"source":"{\n\n\"Vars\":{ \"rows\" :[\n\t\t{\n\t\t\t\"title\":\"title1\",\n\t\t\t\"bodies\":[\"1\",\"2\",\"3\",\"4\"]\n\t\t},\n\t\t{\n\t\t\t\"title\":\"title2\",\n\t\t\t\"bodies\":[\"5\",\"6\"]\n\t\t}]\n\t}\n\n}\n","lang":"json"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"b","attributes":{},"children":["Template"]}," ","The syntax is:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"./code_snippets/multi_array.html","language":"html","title":"","header":{"title":"","controls":{"copy":{}}},"lang":"html","source":"Hello {% for row in var:rows %} loop1:{{ row.title }} {% for body in row.bodies\n%} loop2:{{ body }} {% endfor %} {% endfor %}"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The syntax is:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"./code_snippets/multi_array1.html","language":"html","title":"HTML result","header":{"title":"HTML result","controls":{"copy":{}}},"lang":"html","source":"Hello\n\tloop1:title1\n\t\tloop2:1\n\t\tloop2:2\n\t\tloop2:3\n\t\tloop2:4\n\tloop1:title2\n\t\tloop2:5\n\t\tloop2:6"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"multiple-array","__idx":27},"children":["Multiple array"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"json","header":{"controls":{"copy":{}}},"source":"{\n\n\"Vars\":{\n\t\"array1\":[\"1\", \"2\"] ,\n\t\"array2\":[\"3\", \"4\"]\n\t}\n\n}\n","lang":"json"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"b","attributes":{},"children":["Template"]}," ","The syntax is:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"./code_snippets/multiple_array.html","language":"html","title":"","header":{"title":"","controls":{"copy":{}}},"lang":"html","source":"Hello {% for x3 in var:array1 %} loop1:{{ x3 }} {% for x4 in var:array2 %}\nloop2:{{ x4 }} {% endfor %} {% endfor %}"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The syntax is:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"./code_snippets/multiple_array2.html","language":"html","title":"HTML result","header":{"title":"HTML result","controls":{"copy":{}}},"lang":"html","source":"Hello\n\tloop1:1\n\t\tloop2:3\n\t\tloop2:4\n\tloop1:2\n\t\tloop2:3\n\t\tloop2:4"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"mailjets-markup-language-mjml","__idx":28},"children":["Mailjet's Markup Language (MJML)"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This section will show you how to leverage Mailjet's mark-up language MJML which helps you design responsive emails easily. You will be able to see how to leverage our Template language and create multifunctional template, similar to the one shown in Passport."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"printing-a-variable","__idx":29},"children":["Printing a variable"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You can print the value for a variable by adding the template language syntax directly in the MJML part. For example:"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The syntax is:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"./code_snippets/mjml_1.html","language":"html","title":"","header":{"title":"","controls":{"copy":{}}},"lang":"html","source":"<mj-text\n  align=\"center\"\n  color=\"#FFF\"\n  font-size=\"13\"\n  word-wrap=\"break-word\"\n  font-family=\"Helvetica\"\n  vertical-align=\"middle\"\n  padding-left=\"25\"\n  padding-right=\"25\"\n  padding-bottom=\"10\"\n  padding-top=\"10\"\n>\n  Dear {{data:firstName:\"\"}},\n</mj-text>"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["When adding ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["conditional statement"]}," or l",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["oop statement"]},", you need to add the tags ",{"$$mdtype":"Tag","name":"mj-raw","attributes":{},"children":[" "]}," before opening bracket and after the closing bracket. For example:"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The syntax is:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"./code_snippets/mjml_conditional.html","language":"html","title":"For conditional statements","header":{"title":"For conditional statements","controls":{"copy":{}}},"lang":"html","source":"<mj-raw>{% if var:step == \"confirmorder\" %} </mj-raw>\n<mj-section\n  background-color=\"#356cc7\"\n  vertical-align=\"middle\"\n  padding-bottom=\"5\"\n  padding-top=\"0\"\n>\n  <mj-column vertical-align=\"middle\" width=\"100%\">\n    <mj-text\n      align=\"center\"\n      color=\"#FFF\"\n      font-size=\"13\"\n      word-wrap=\"break-word\"\n      font-family=\"Helvetica\"\n      vertical-align=\"middle\"\n      padding-left=\"25\"\n      padding-right=\"25\"\n      padding-bottom=\"10\"\n      padding-top=\"10\"\n    >\n      Thank you very much for your purchase.<br />\n      Please find the receipt below.\n    </mj-text>\n  </mj-column>\n</mj-section>\n<mj-raw> {% elseif var:step == \"unavailable\" %} </mj-raw>\n<mj-section background-color=\"#356CC7\" padding-bottom=\"0\" padding-top=\"10\">\n  <mj-text\n    align=\"center\"\n    color=\"#FfF\"\n    font-size=\"13\"\n    word-wrap=\"break-word\"\n    font-family=\"Helvetica\"\n    vertical-align=\"middle\"\n    padding-left=\"25\"\n    padding-right=\"25\"\n    padding-bottom=\"10\"\n    padding-top=\"10\"\n  >\n    We apologize, the product is out of stock.<br />\n  </mj-text>\n</mj-section>\n<mj-raw> {% endif %} </mj-raw>"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You can find the design of this template, along with many other ready-to-go template samples on the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://mjml.io/templates"},"children":["MJML website"]},". You can use them as they are or take inspiration to create your own amazing template!"]}]},"headings":[{"value":"Template Language Reference","id":"template-language-reference","depth":1},{"value":"Delimitators","id":"delimitators","depth":2},{"value":"Operators","id":"operators","depth":2},{"value":"Arithmetic Operators:","id":"arithmetic-operators","depth":4},{"value":"Comparison Operators:","id":"comparison-operators","depth":4},{"value":"Logical Operators","id":"logical-operators","depth":4},{"value":"Variables","id":"variables","depth":2},{"value":"Vars and Custom Vars","id":"vars-and-custom-vars","depth":3},{"value":"Template","id":"template","depth":4},{"value":"HTML Result","id":"html-result","depth":4},{"value":"Contact Properties","id":"contact-properties","depth":3},{"value":"Predefined static variables","id":"predefined-static-variables","depth":3},{"value":"mj:contact","id":"mjcontact","depth":4},{"value":"mj:sender","id":"mjsender","depth":4},{"value":"mj:template","id":"mjtemplate","depth":4},{"value":"More","id":"more","depth":4},{"value":"Segmentation","id":"segmentation","depth":2},{"value":"Functions","id":"functions","depth":2},{"value":"Behavior of the contact","id":"behavior-of-the-contact","depth":3},{"value":"String modification","id":"string-modification","depth":3},{"value":"Mathmatical function","id":"mathmatical-function","depth":3},{"value":"Formatting functions","id":"formatting-functions","depth":3},{"value":"Encoding and Formatting","id":"encoding-and-formatting","depth":3},{"value":"Conditional Statements","id":"conditional-statements","depth":2},{"value":"Set function","id":"set-function","depth":2},{"value":"Loop Statements","id":"loop-statements","depth":2},{"value":"Multidimensional array","id":"multidimensional-array","depth":2},{"value":"Multiple array","id":"multiple-array","depth":2},{"value":"Mailjet's Markup Language (MJML)","id":"mailjets-markup-language-mjml","depth":2},{"value":"Printing a variable","id":"printing-a-variable","depth":3}],"frontmatter":{"title":"Templating Language Reference","seo":{"description":"Full syntax reference for Mailjet template language: delimitators, arithmetic and logical operators, var/data/mj namespaces, functions, and control structures.","title":"Template Language Reference"}},"lastModified":"2026-08-26T10:53:57.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/docs/email-api/template_language/template_reference","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}