Substitution and Section Tags
Info
If you prefer to use Twilio SendGrid Dynamic Transactional Templates and Marketing Campaigns designs, use Handlebars.
Substitution tags and section tags personalize your email content per recipient. A substitution tag is a placeholder that SendGrid replaces with recipient-specific data, while a section tag references a reusable block of content. The following examples show how to use both.
This example creates a name substitution for your emails using the tag -name-, which is replaced with the name of the recipient.
Hello -name-,
1<html>2<head></head>3<body>4<p>Hello -name-,<br /></p>5</body>6</html>
1{2"to": ["john@domain.com", "jane@domain.com", "matt@domain.com"],3"sub": {4"-name-": ["John", "Jane", "Matt"]5}6}
1{2"personalizations": [3{4"to": [5{6"email": "john@domain.com",7"name": "John"8}9],10"subject": "Example 01",11"substitutions": {12"-name-": "John"13}14},15{16"to": [17{18"email": "jane@domain.com",19"name": "Jane"20}21],22"subject": "Example 02",23"substitutions": {24"-name-": "Jane"25}26},27{28"to": [29{30"email": "matt@domain.com",31"name": "Matt"32}33],34"subject": "Example 03",35"substitutions": {36"-name-": "Matt"37}38}39],40"from": {41"email": "sender@senddomain.com",42"name": "Sender"43},44"reply_to": {45"email": "sender@senddomain.com",46"name": "Sender"47},48"subject": "Example",49"content": [50{51"type": "text/plain",52"value": "Hello -name-,"53},54{55"type": "text/html",56"value": "Hello -name-,"57}58]59}
Hello John,
1<html>2<head></head>3<body>4<p>Hello John,<br /></p>5</body>6</html>
Hello Jane,
1<html>2<head></head>3<body>4<p>Hello Jane,<br /></p>5</body>6</html>
Hello Matt,
1<html>2<head></head>3<body>4<p>Hello Matt,<br /></p>5</body>6</html>
This example will show you how to create a first name and last name substitution for your emails. We will be using the tags -first_name- and -last_name- in this example. In this example the tag -first_name- will get replaced with the first name of the recipient and the tag -last_name- will get replaced with the last name of the recipient.
Hello -first_name- -last_name-,
1<html>2<head></head>3<body>4<p>Hello -first_name- -last_name-,<br /></p>5</body>6</html>
1{2"to": [3"john.smith@domain.com",4"jane.williams@domain.com",5"matt.johnson@domain.com"6],7"sub": {8"-first_name-": ["John", "Jane", "Matt"],9"-last_name-": ["Smith", "Williams", "Johnson"]10}11}
1{2"personalizations": [3{4"to": [5{6"email": "john.smith@domain.com",7"name": "John Smith"8}9],10"subject": "Example 01",11"substitutions": {12"-first_name-": "John",13"-last_name-": "Smith"14}15},16{17"to": [18{19"email": "jane.williams@domain.com",20"name": "Jane Williams"21}22],23"subject": "Example 02",24"substitutions": {25"-first_name-": "Jane",26"-last_name-": "Williams"27}28},29{30"to": [31{32"email": "matt.johnson@domain.com",33"name": "Matt Johnson"34}35],36"subject": "Example 03",37"substitutions": {38"-first_name-": "Matt",39"-last_name-": "Johnson"40}41}42],43"from": {44"email": "sender@senddomain.com",45"name": "Sender"46},47"reply_to": {48"email": "sender@senddomain.com",49"name": "Sender"50},51"subject": "Example",52"content": [53{54"type": "text/plain",55"value": "Hello -first_name- -last_name-,"56},57{58"type": "text/html",59"value": "Hello -first_name- -last_name-,"60}61]62}
Hello John Smith,
1<html>2<head></head>3<body>4<p>Hello John Smith,<br /></p>5</body>6</html>
Hello Jane Williams,
1<html>2<head></head>3<body>4<p>Hello Jane Williams,<br /></p>5</body>6</html>
Hello Matt Johnson,
1<html>2<head></head>3<body>4<p>Hello Matt Johnson,<br /></p>5</body>6</html>
Danger
Due to low usage, the Section Tags feature has been deprecated and removed. For more information, see Retired mail settings.
This example will show you how to create a section as a greeting with a name substitution. We will be using the tags -warm_welcome-, -greeting- and -name- in this example. In this example, we have created a greeting using the section tag -warm_welcome-. The -warm_welcome- tag is replaced with the -greeting- substitution which calls the section "Hello -name-,". The -name- tag in "Hello -name-," is then replaced with the recipient's name.
-warm_welcome-
1<html>2<head></head>3<body>4<p>-warm_welcome-<br /></p>5</body>6</html>
1{2"to": ["john@domain.com", "jane@domain.com", "matt@domain.com"],3"sub": {4"-name-": ["John", "Jane", "Matt"],5"-warm_welcome-": ["-greeting-", "-greeting-", "-greeting-"]6},7"section": {8"-greeting-": "Hello -name-,"9}10}
1{2"personalizations": [3{4"to": [5{6"email": "john@domain.com",7"name": "John"8}9],10"subject": "Example 01",11"substitutions": {12"-name-": "John",13"-warm_welcome-": "-greeting-"14}15},16{17"to": [18{19"email": "jane@domain.com",20"name": "Jane"21}22],23"subject": "Example 02",24"substitutions": {25"-name-": "Jane",26"-warm_welcome-": "-greeting-"27}28},29{30"to": [31{32"email": "matt@domain.com",33"name": "Matt"34}35],36"subject": "Example 03",37"substitutions": {38"-name-": "Matt",39"-warm_welcome-": "-greeting-"40}41}42],43"from": {44"email": "sender@senddomain.com",45"name": "Sender"46},47"reply_to": {48"email": "sender@senddomain.com",49"name": "Sender"50},51"subject": "Example",52"content": [53{54"type": "text/plain",55"value": "-warm_welcome-"56},57{58"type": "text/html",59"value": "<html>\n <head></head>\n <body>\n <p>-warm_welcome- \n </p>\n </body>\n</html>"60}61],62"sections": {63"-greeting-": "Welcome -name-,"64}65}
john@domain.com
Hello John,
1<html>2<head></head>3<body>4<p>Hello John,<br /></p>5</body>6</html>
Hello Jane,
1<html>2<head></head>3<body>4<p>Hello Jane,<br /></p>5</body>6</html>
Hello Matt,
1<html>2<head></head>3<body>4<p>Hello Matt,<br /></p>5</body>6</html>
This example will show you how to create a section with first name and last name substitution for your emails. We will be using the tags -warm_welcome-, -greeting-, -first_name- and -last_name- in this example. In this example, we have created a greeting using the section tag -warm_welcome-. The -warm_welcome- tag is replaced with the -greeting- substitution which calls the section "Hello -first_name- -last_name-,". The -first_name- and -last_name- tags in "Hello -first_name- -last_name-," is then replaced with the recipients first and last names.
-warm_welcome-
1<html>2<head></head>3<body>4<p>-warm_welcome-<br /></p>5</body>6</html>
1{2"to": [3"john.smith@domain.com",4"jane.williams@domain.com",5"matt.johnson@domain.com"6],7"sub": {8"-first_name-": ["John", "Jane", "Matt"],9"-last_name-": ["Smith", "Williams", "Johnson"],10"-warm_welcome-": ["-greeting-", "-greeting-", "-greeting-"]11},12"section": {13"-greeting-": "Hello -first_name- -last_name-,"14}15}
1{2"personalizations": [3{4"to": [5{6"email": "john.smith@domain.com",7"name": "John Smith"8}9],10"subject": "Example 01",11"substitutions": {12"-first_name-": "John",13"-last_name-": "Smith",14"-warm_welcome-": "-greeting-"15}16},17{18"to": [19{20"email": "jane.williams@domain.com",21"name": "Jane Williams"22}23],24"subject": "Example 02",25"substitutions": {26"-first_name-": "Jane",27"-last_name-": "Williams",28"-warm_welcome-": "-greeting-"29}30},31{32"to": [33{34"email": "matt.johnson@domain.com",35"name": "Matt Johnson"36}37],38"subject": "Example 03",39"substitutions": {40"-first_name-": "Matt",41"-last_name-": "Johnson",42"-warm_welcome-": "-greeting-"43}44}45],46"from": {47"email": "sender@senddomain.com",48"name": "Sender"49},50"reply_to": {51"email": "sender@senddomain.com",52"name": "Sender"53},54"subject": "Example",55"content": [56{57"type": "text/plain",58"value": "-warm_welcome-"59},60{61"type": "text/html",62"value": "<html>\n <head></head>\n <body>\n <p>-warm_welcome- \n </p>\n </body>\n</html>"63}64],65"sections": {66"-greeting-": "Welcome -first_name- -last_name-,"67}68}
john.smith@domain.com
Hello John Smith,
1<html>2<head></head>3<body>4<p>Hello John Smith,<br /></p>5</body>6</html>
Hello Jane Williams,
1<html>2<head></head>3<body>4<p>Hello Jane Williams,<br /></p>5</body>6</html>
Hello Matt Johnson,
1<html>2<head></head>3<body>4<p>Hello Matt Johnson,<br /></p>5</body>6</html>
This example will show you how to create three different sections, each with first name and last name substitution for your emails. We will be using the tags -warm_welcome-, -greeting01-, -greeting02-, -greeting03-, -first_name- and -last_name- in this example. In this example, we have created three different greetings using the section tag -warm_welcome-. The -warm_welcome- tag is replaced with either -greeting01-, -greeting02- or -greeting03- substitution. This will call one of the three sections. In each of these sections, there is the -first_name- and -last_name- tags which will get replaced with the recipients first and last names.
-warm_welcome-
1<html>2<head></head>3<body>4<p>-warm_welcome-<br /></p>5</body>6</html>
1{2"to": [3"john.smith@domain.com",4"jane.williams@domain.com",5"matt.johnson@domain.com"6],7"sub": {8"-first_name-": ["John", "Jane", "Matt"],9"-last_name-": ["Smith", "Williams", "Johnson"],10"-warm_welcome-": ["-greeting01-", "-greeting02-", "-greeting03-"]11},12"section": {13"-greeting01-": "Welcome -first_name- -last_name-,",14"-greeting02-": "Hello -first_name- -last_name-,",15"-greeting03-": "Dear -first_name- -last_name-,"16}17}
1{2"personalizations": [3{4"to": [5{6"email": "john.smith@domain.com",7"name": "John Smith"8}9],10"subject": "Example 01",11"substitutions": {12"-first_name-": "John",13"-last_name-": "Smith",14"-warm_welcome-": "-greeting01-"15}16},17{18"to": [19{20"email": "jane.williams@domain.com",21"name": "Jane Williams"22}23],24"subject": "Example 02",25"substitutions": {26"-first_name-": "Jane",27"-last_name-": "Williams",28"-warm_welcome-": "-greeting02-"29}30},31{32"to": [33{34"email": "matt.johnson@domain.com",35"name": "Matt Johnson"36}37],38"subject": "Example 03",39"substitutions": {40"-first_name-": "Matt",41"-last_name-": "Johnson",42"-warm_welcome-": "-greeting03-"43}44}45],46"from": {47"email": "sender@senddomain.com",48"name": "Sender"49},50"reply_to": {51"email": "sender@senddomain.com",52"name": "Sender"53},54"subject": "Example",55"content": [56{57"type": "text/plain",58"value": "-warm_welcome-"59},60{61"type": "text/html",62"value": "<html>\n <head></head>\n <body>\n <p>-warm_welcome- \n </p>\n </body>\n</html>"63}64],65"sections": {66"-greeting01-": "Welcome -first_name- -last_name-,",67"-greeting02-": "Hello -first_name- -last_name-,",68"-greeting03-": "Dear -first_name- -last_name-,"69}70}
Welcome John Smith,
1<html>2<head></head>3<body>4<p>Welcome John Smith,<br /></p>5</body>6</html>
Hello Jane Williams,
1<html>2<head></head>3<body>4<p>Hello Jane Williams,<br /></p>5</body>6</html>
Dear Matt Johnson,
1<html>2<head></head>3<body>4<p>Dear Matt Johnson,<br /></p>5</body>6</html>
This example will show you how to create three different sections for confirmation emails. We will be using the tags -name-, -confirmations-, -confirmation_001-, -confirmation_002-, -confirmation_003- and -order_id- in this example. In this example, we have created three different confirmations using the section tag -confirmations-. The -confirmations- tag is replaced with either -confirmation_001-, -confirmation_002- or -confirmation_003- substitution. This will call one of the three sections. In each of these sections, there is the -order_id- tag which will get replaced with the recipient's order id.
1Hello -name-,2-confirmations-
1<html>2<head></head>3<body>4<p>5Hello -name-,<br />6-confirmations-7</p>8</body>9</html>
1{2"to": ["john@domain.com", "jane@domain.com", "matt@domain.com"],3"sub": {4"-name-": ["John", "Jane", "Matt"],5"-confirmations-": [6"-confirmation_001-",7"-confirmation_002-",8"-confirmation_003-"9],10"-order_id-": ["12345", "23456", "34567"]11},12"section": {13"-confirmation_001-": "Thanks for choosing SendGrid. This email is to confirm that we have processed your order -order_id-.",14"-confirmation_002-": "Thanks for choosing SendGrid. This email is to confirm that we have processed your order -order_id-. This invoice is to be paid by bank transfer within 7 days from the date of your monthly statement.",15"-confirmation_003-": "Thanks for choosing SendGrid. This email is to confirm that we have processed your order -order_id-. You can download your invoice as a PDF for your records."16}17}
1{2"personalizations": [3{4"to": [5{6"email": "john@domain.com",7"name": "John"8}9],10"subject": "Example 01",11"substitutions": {12"-name-": "John",13"-order_id-": "12345",14"-confirmations-": "-confirmation_001-"15}16},17{18"to": [19{20"email": "jane@domain.com",21"name": "Jane"22}23],24"subject": "Example 02",25"substitutions": {26"-name-": "Jane",27"-order_id-": "23456",28"-confirmations-": "-confirmation_002-"29}30},31{32"to": [33{34"email": "matt@domain.com",35"name": "Matt"36}37],38"subject": "Example 03",39"substitutions": {40"-name-": "Matt",41"-order_id-": "34567",42"-confirmations-": "-confirmation_003-"43}44}45],46"from": {47"email": "sender@senddomain.com",48"name": "Sender"49},50"reply_to": {51"email": "sender@senddomain.com",52"name": "Sender"53},54"subject": "Example",55"content": [56{57"type": "text/plain",58"value": "Hello -name-,\n-confirmations-"59},60{61"type": "text/html",62"value": "<html>\n <head></head>\n <body>\n <p>Hello -name-, \n -confirmations-</p>\n </body>\n</html>"63}64],65"sections": {66"-confirmation_001-": "Thanks for choosing SendGrid. This email is to confirm that we have processed your order -order_id-.",67"-confirmation_002-": "Thanks for choosing SendGrid. This email is to confirm that we have processed your order -order_id-. This invoice is to be paid by bank transfer within 7 days from the date of your monthly statement.",68"-confirmation_003-": "Thanks for choosing SendGrid. This email is to confirm that we have processed your order -order_id-. You can download your invoice as a PDF for your records."69}70}
1Welcome John,2Thanks for choosing SendGrid. This email is to confirm that we have processed your order 12345.
1<html>2<head></head>3<body>4<p>5Welcome John,<br />6Thanks for choosing SendGrid. This email is to confirm that we have7processed your order 12345.8</p>9</body>10</html>
jane@domain.com
1Hello Jane,2Thanks for choosing SendGrid. This email is to confirm that we have processed your order 23456. This invoice is to be paid by bank transfer within 7 days from the date of your monthly statement.
1<html>2<head></head>3<body>4<p>5Hello Jane,<br />6Thanks for choosing SendGrid. This email is to confirm that we have7processed your order 23456. This invoice is to be paid by bank transfer8within 7 days from the date of your monthly statement.9</p>10</body>11</html>
1Dear Matt,2Thanks for choosing SendGrid. This email is to confirm that we have processed your order 34567. You can download your invoice as a PDF for your records.
1<html>2<head></head>3<body>4<p>5Dear Matt,<br />6Thanks for choosing SendGrid. This email is to confirm that we have7processed your order 34567. You can download your invoice as a PDF for8your records.9</p>10</body>11</html>