forked from HowToSFMC/AMPscript_materials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AMPscriptBasics-onesheet.html
217 lines (115 loc) · 4.04 KB
/
AMPscriptBasics-onesheet.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<!-- AMPscript Elements -->
%%[ /* AMPscript block delimiters */
var @email, @pet
SET @email = AttributeValue('EmailAddress')
SET @pet = AttributeValue('pet')
IF Empty(@email) THEN
SET @email = emailaddr
ENDIF
IF NOT Empty(@pet) THEN
SET @favPet = @pet
ELSEIF NOT Empty(@favPet) THEN
SET @favPet = Propercase(@favPet)
ELSE
SET @favPet = "Tell us you at least like animals, please?"
ENDIF
]%%
<td><!-- AMPscript inline delimiters -->
%%=v(@email)=%%
</td>
<td><!-- Personalization Strings - Stand alone -->
<ul>
<li>%%firstname%%</li>
<li>%%emailaddr%%</li>
</ul>
</td>
%%[/* Personalization Strings - In AMPscript */
SET @firstName = firstname
SET @emailAddress = emailaddr
]%%
%%[ /* Commonly used personalization strings */
SET @emailAddress = emailaddr
SET @emailName = emailname_ /* commonly used for send logs */
SET @currentYear = xtyear /* regularly used for copy right year */
SET @messageContext = _messagecontext /* used for displaying content specific to the location of display - preview screen; landing page; inbox; etc */
SET @jobID = jobid /* commonly used for send logs */
SET @viewEmailInBrowser = view_email_url
SET @defaultProfileCenter = profile_center_url
SET @defaultUnsubscribe = unsub_center_url
SET @addtionalAttribute = __AdditionalEmailAttribute1 /* used to bring in data defined in the properties pane of an email */
]%%
%%[ /* Comparison operator examples: */
var @date1, @date2
SET @date1 = Format(Now(), MM/dd/yyyy) /* today's date */
SET @date2 = Format(01/01/2020, MM/dd/yyyy)
/* Equal (==) or Not Equal (!=) */
IF @date1 == @date2 Then
SET @comparisonOutput1 = 'equal'
ElseIf @date1 != @date2 Then
SET @comparisonOutput1 = 'not equal'
EndIf
Output(Concat('<br>Result: ', @comparisonOutput1))
/* Greater Than (>) or Less Than (<) */
IF @date1 > @date2 Then
SET @comparisonOutput2 = 'greater than'
ElseIf @date1 < @date2 Then
SET @comparisonOutput2 = 'less than'
EndIf
Output(Concat('<br>Result: ', @comparisonOutput2))
/* Greater Than or Equal To (>=) or Less Than or Equal To (<=) */
IF @date1 >= @date2 Then
SET @comparisonOutput3 = 'greater than or equal to'
ElseIf @date1 <= @date2 Then
SET @comparisonOutput3 = 'less than or equal to'
EndIf
Output(Concat('<br>Result: ', @comparisonOutput3))
]%%
%[ /* Logic operator examples: */
var @text1, @text2
SET @text1 = 'This'
SET @text2 = 'That'
/* AND operator */
If @text1 == 'This' AND @text2 == 'That' Then
SET @logicOutput1 = Concat(@text1, ' and ', @text2)
EndIf
Output(Concat('<br>Result: ', @logicOutput1))
/* OR operator */
If @text1 == 'This' OR @text1 == 'That' Then
SET @logicOutput2 = Concat(@text1, ' or ', @text2)
EndIf
Output(Concat('<br>Result: ', @logicOutput2))
/* NOT operator */
If NOT Empty(@text1) Then
SET @logicOutput3 = Concat(@text1, ' or ', @text2)
EndIf
Output(Concat('<br>Result: ', @logicOutput3))
]%%
%%[ /* Data types and their delimiters */
var @string, @date, @number1, @number2, @boolean1, @boolean2
SET @string = 'String values are wrapped in quotes'
SET @date = Format(Now(), MM/dd/yyyy)
SET @number1 = 1
SET @number2 = 1.6
SET @boolean1 = 'True'
SET @boolean2 = 0
]%%
%%[ /* Conditional Operators - Logic IF Statements */
IF /* open of conditional statement */
Length(@argument1) > 0 /* expression to be evaluated */
THEN /* do not forget to add your then clause */
@result /* out put if expression is found to be true */
ELSE
]%%
%%[ /* Frequently used string function examples */
/* Concatenate - this is the exact same format as VB or Excel */
SET @concatString = Concat(@text1, @text2) /* output: "ThisThat" */
/* Format - best to use to format currency or dates */
SET @formatDate = Format(Now(), yyyyMMdd) /* output: 20200623 */
SET @formatCurrency = Format(8.99, 'C', 'en-US') /* output: */
]%%
%%[ /* */ ]%%
%%[ /* Math function examples */
/* Addition */
]%%
%%[/* Content function samples */]%%
%%=ContentBlockbyId("1234")=%%