In my email, I am calling a Content Block. The content block uses a lookup to pull out content from a Data Extension.

Example code in content block:

set @SourceDE                = "DE_NAME"             
set @subjectLine             = Lookup(@SourceDE,"subl","locale",@locale)

..........similarly pulls out other content like pre-header, header text etc. from SourceDE

I call this block from my email. This method works perfectly.

But what I want now is that I should be able to change the source DE in email and not in Content Block. Then from the email the source DE should be dynamically set in Content Block.

expected outcome

In email

 set @SourceDE                = "NEW_DE_NAME" 

In content block

 set @subjectLine             = Lookup(@SourceDE,"subl","locale",@locale)

Content block should fetch the Data Extension name from the email

So by doing this I can change the name of the source DE directly in the email & also re-use the content block for other emails.

Please can anyone help me how to do this?

1 Answer 1


Ampscript gets evaluated top to bottom. So any declaration of variable further down in your code (whether it is within the email itself, or in a referenced content block) will always overwrite any declarations of same variable further up in your code.

How I would do this, to make this more robust, is to check if @sourceDE is already declared, when looking it up in your content block. So:

In email:

SET @sourceDE = "NEW_DE_NAME"

In content block:

SET @subjectLine = LOOKUP(@SourceDE,"subl","locale",@locale)

In this case, you will only set the DE name in content block if it for some reason gets included in an email without an existing declaration of @sourceDE. Otherwise it will take the @sourceDE value set in the email, before the content block is referenced.

You must log in to answer this question.

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