← Back to Snippets
AMPScript

ContentBlockByKey

A modular architecture pattern using ContentBlockByKey to load reusable content assets dynamically based on subscriber context, facilitating easier maintenance than ContentBlockByID.


JavaScript
%%[
    /* Define context variables to be used inside the block */
    SET @CampaignName = "Winter_Sale_2025"
    
    /* Dynamically load content based on a logic variable */
    SET @footerKey = Concat("Footer_", @UserRegion) 
    
    /* Fallback if region is empty */
    IF Empty(@UserRegion) THEN SET @footerKey = "Footer_Global" ENDIF
    
    SET @content = ContentBlockByKey(@footerKey)
]%%
<div class="footer-wrapper">
    %%=v(@content)=%%
</div>