Span Server-Side JavaScript Blocks with AMPScript Control Statements

Server-side JavaScript blocks can span these content types:

  • HTML
  • Text
  • Personalization Strings
  • AMPscript

Use this sample code as an example to construct your own content. Close all script blocks before moving on to the next content type.

1<script runat=server language=javascript>
2var Count = 0;
3if (Count < 1)
4{
5</script>
6    <p> If Case </p>
7    %%[
8        VAR @v1         SET @v1 = 0         FOR @v1 = 1 TO 5 DO]%%
9            <p>This is loop %%=v(@v1)=%% </p>
10        %%[ NEXT ]%%
11<script runat=server language=javascript>
12}
13else if (Count > 1)
14{
15</script>
16    <p> Else If Case </p>
17<script runat=server>
18}
19else
20{
21</script>
22    <p> Else Case </p>
23<script runat=server>
24}
25</script>