0

can I dynamically change/replace "mycontentblock" in %%=ContentBlockbyKey("myContentBlock")=%% in with ampscript variable in landing pages - eg : %%=ContentBlockbyKey("@contentname")=%%.its not work for me! any other idea!

  • You just need to remove the double quotes around @contentname and as long as the value of that var is the Content Block's key, it will work. – Gortonington May 10 '18 at 11:52
  • Thanks, @Gortonington. can I use dynamic content block in landing page too? – Karuppasamy May 10 '18 at 12:04
  • yes - you just set the variable @contentname inside a conditional statement that will fill in the appropriate key depending on your requirements. – Gortonington May 10 '18 at 12:32
  • @Gortonington -But, conditional statement only profile attributes or DE attributes, how to set ampscript variable? and I just check in trailblazer community - Dynamic content in landing pages that still in idea section only - success.salesforce.com/ideaView?id=0873A000000lKsZQAU , did you implemented anywhere. – Karuppasamy May 10 '18 at 12:35
  • you do like this: SET @var = AttributeValue("yourVar") [or if not via MicrositeURL() then via a Lookup()] and then IF @var == "var1" THEN set @contentname = "content1" ELSE SET @contentname = "defaultcontent" ENDIF – Gortonington May 10 '18 at 12:44
2

Did you try to use the other content functions like ContentBlockbyId or ContentBlockbyName?

Also I recommend you to decompose your code in first declaring the variable and then calling the content. You can do it in one of course but to start it is easier to debug.

ContentBlockbyId

First retrieve the ID of the content box:

enter image description here

Add this code in your landing page:

%%[ 
SET @ContentID = "58512" 
SET @Content = ContentBlockbyID(@ContentID) 
]%% 

%%=TreatAsContent(@Content)=%%

OR

%%[ 
SET @ContentID = "58512" 
output(ContentBlockbyID(@ContentID)) 
]%%

ContentBlockbyName

First retrieve the path of the content box: enter image description here

Add this code in your landing page:

%%[ 
SET @ContentName = "Shared Content\Master Template\Assets\Content Blocks\Big CTA" 
]%% 

%%=ContentBlockByName(@ContentName)=%%

If you want this to be dynamic, you will have to modify the @ContentID or @ContentName. Make sure to set a default content in case you dynamic value does not match an actual content.

This should help you get started.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.