0

I need to have a nested if statement with some HTML inside.

Like this.

%%[ IF (NOT EMPTY(@Var1) THEN ]%%
    <!-- HTML goes here -->
        %%[ IF (NOT EMPTY(@Var2) THEN
        <!-- HTML goes here -->
        %%[ ENDIF ]%%
    <!-- HTML goes here -->
%%[ ENDIF ]%%

But if I try to set it like this I'm getting an error that the first IF statement is never closed and the code doesen't work.

What am I doing wrong? I was under the impression that AmpScript has the option to use nested if statements. Is it a syntax error or am I approaching this the wrong way?

1 Answer 1

1

I think you are not closing a %%[ on line number 4. You are missing two ) on line 1 and 3 too.

Try this:

%%[ IF (NOT EMPTY(@Var1)) THEN ]%%
    <!-- HTML goes here -->
        %%[ IF (NOT EMPTY(@Var2)) THEN ]%%
        <!-- HTML goes here -->
        %%[ ENDIF ]%%
    <!-- HTML goes here -->
%%[ ENDIF ]%%
3
  • Sorry, I copied it in a rush from the project and simplifying the code I missed some stuff. I checked the project and it is like in your example so I edited the question to fix the problem. The error message is still there, sadly.
    – banjug
    Dec 9, 2022 at 14:23
  • Are you sure it's exactly like my example? I've just tested it in Content Builder and it's working fine. Can you post your full code? Maybe something is missing elsewhere ... Dec 9, 2022 at 14:30
  • 1
    It was actually one of the opening parentheses missing, I rolled back the question to the original state for clarity. Thank you.
    – banjug
    Dec 9, 2022 at 14:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .