0

I have a problem with this Loop because there are 8 rows in the DE and when I execute the code below, the preview only shows 6 content blocks.

The last one it displays, also has a loop inside and calls another content block by Id.

Is that something that affects it? I think it does, because if instead of %%=ContentBlockbyId(@contentBlockId)=%% I add %%=v(@contentBlockId)=%% I get 8 results, one Id per row.

What can I do so that this loops finish with all the content and does not ends if a content has a loop inside?

%%=ContentBlockById('162810')=%% -->This is an AMPScript content code outside DE <--

%%[
VAR @ContentRows, @ContentRow, @RowCount, @numRowsToReturn, @RowCounter, @emailName

SET @numRowsToReturn = 0
SET @emailName = "XYZ_Order_Confirmation_Email"
SET @ContentRows = LookupOrderedRows("XYZ_Content_Blocks_Order_Coco", @numRowsToReturn, "ContentOrder asc", "Email", @emailName)
set @RowCount = rowcount(@ContentRows)

IF @rowCount > 0 THEN

  FOR @RowCounter = 1 TO @rowCount DO

    VAR @contentBlockId, @contentBlock
    SET @ContentRow = row(@ContentRows, @RowCounter)
    SET @contentBlockId = field(@ContentRow,"ContentId")
 
 ]%%


%%=ContentBlockbyId(@contentBlockId)=%%


%%[ NEXT @RowCounter ]%%

%%[ ELSE ]%%

No rows found

%%[ ENDIF ]%%

1 Answer 1

2

I'll throw out a guess that you're you're reusing variable names in your sub-blocks -- like @RowCounter.

I'd output that value in your loop to see if that's the case.

%%=ContentBlockById('162810')=%% 

%%[
VAR @ContentRows, @ContentRow, @RowCount, @numRowsToReturn, @RowCounter, @emailName

SET @numRowsToReturn = 0
SET @emailName = "XYZ_Order_Confirmation_Email"
SET @ContentRows = LookupOrderedRows("XYZ_Content_Blocks_Order_Coco", @numRowsToReturn, "ContentOrder asc", "Email", @emailName)
set @RowCount = rowcount(@ContentRows)

IF @rowCount > 0 THEN

  FOR @RowCounter = 1 TO @rowCount DO

    output(concat("<br>rowcounter: ", @rowCounter, "<hr>")

    VAR @contentBlockId, @contentBlock
    SET @ContentRow = row(@ContentRows, @RowCounter)
    SET @contentBlockId = field(@ContentRow,"ContentId")
 
 ]%%


 %%=ContentBlockbyId(@contentBlockId)=%%


%%[ NEXT @RowCounter ]%%

%%[ ELSE ]%%

No rows found

%%[ ENDIF ]%%

I know you didn't ask this, but architecturally speaking, resist the temptation to modularize your emails using lookups to data extensions. You'll drive yourself crazy with abstract and mysterious problems like this. Plus whomever is tasked with a wholesale change to the design will curse you under their breath. Someone please fight me on this. My dukes are up.

You must log in to answer this question.

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