I have successfully been able to show/hide drag-and-drop content blocks on a cloudpage by doing the following:

  1. Adding an HTML block with opening IF statement
  2. Adding in a Image block with the image
  3. Adding another HTML block with closing ENDIF

In the builder, it looks like the image below:

enter image description here

This works fine on a cloudpage.

I am trying to do the exact same thing in an email built using content builder but I get an error saying there is a missing ENDIF.

Does this not function the same way in content builder for emails? Is there another way to do this?

I have gotten it to work by creating a content block with the content that I then reference, as below:

%%[ IF NOT EMPTY(AttributeValue('Recommendations')) THEN ]%%

However, this adds a bit of overhead with managing various content blocks outside of the email itself and would prefer to have it work the way I described above for the sake of my users.

  • 1
    Recently had the same issue ;) What i thought about was incorporating the conditional ampscript inside the contentblock itself. But there is some downside to this because you cannot really do it with the layouts from salesforce. If you are just inserting an html block it works really well though. If you can you might wanna grab the HTML from your contentblock and paste these ampscript lines into it. Feb 17, 2021 at 6:13
  • Thanks for the suggestion. Will give this a try.
    – Ben
    Feb 17, 2021 at 23:00

1 Answer 1


If you are just using Attributes from a Data Extension or Profile Attributes from All Subscribers, you can use the built in Dynamic Content Block in Content Builder. This will create your IF statement for you. The main caveat being that it cannot do anything with AMPScript variables at all and that it requires each block to be a separate content block.

You can leave the 'default content' empty, which will mean that it will default to a null block (or hide) and then you put your Rule 1 to the data extension attribute you want (in my example I chose 'FirstName') and then push in the content block you want to show.

enter image description here

If this is still too much overhead due to the requirement to create a content block for each, you can go into the HTML Editor section of each block you create and just put your AMPScript before/after inside here.

Example on an Image Block:

enter image description here

Just be careful because some blocks can move the AMPscript around and may make things a bit 'wonky'. In those cases, I have found using the <script runat=server language=AMPscript> and </script> instead of %%[ and ]%% take care of it.

  • Thanks yes also played around with dynamic content block. Might try your idea of dumping it in the html editor, but as you say I've seen some funny behaviour with this sometimes when the block is edited using the UI, the html can jump around/things get magically removed from the html editor.
    – Ben
    Feb 17, 2021 at 22:59

You must log in to answer this question.

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