2

Here is a simplified example: I have some values set for multiple products in an email:

set @product1 = "Name of product one"
set @product1link = "URL for product 1"
set @product2 = "Name of product two"
set @product2link = "URL for product 2" 
set @product3 = "Name of product three"
set @product3link = "URL for product 3" 
set @product4 = "Name of product four"
set @product4link = "URL for product 4"

The loop picks up each product:

%%[
set @myCount = 0
set @totalProducts = 4
]%%
%%[ FOR @myCount = 1 TO @totalProducts DO ]%%
        %%[
        set @productTitle = Concat("@product",@myCount)
        ]%%
            <h1>%%=v(@productTitle)=%%</h1> 
%%[ NEXT ]%% 

What I expected to get would be:

Name of product one
Name of product two
Name of product three
Name of product four

The output I get is:

@product1
@product2
@product3
@product4

How can I set @productTitle so that it will get the value set for each product?

2 Answers 2

4
    %%[
        Set @product1 = "Name of product one"
        Set @product1link = "URL for product 1"
        Set @product2 = "Name of product two"
        Set @product2link = "URL for product 2" 
        Set @product3 = "Name of product three"
        Set @product3link = "URL for product 3" 
        Set @product4 = "Name of product four"
        Set @product4link = "URL for product 4"

        Set @myCount = 0
        Set @totalProducts = 4

        For @myCount = 1 To @totalProducts Do
            Set @declaredValue = Concat('%%=v(@product',@myCount,')=%%')
    ]%%
        %%=TreatAsContent(@declaredValue)=%%<br>
    %%[
        Next @myCount 
    ]%% 

This produced an output of:

Name of product one
Name of product two
Name of product three
Name of product four

1
  • Thanks. Nice shot!
    – mario ruiz
    Aug 13, 2020 at 22:18
0

Looks like your original code was nearly there, just remove the ""s when you concat @product, otherwise it will be treated as a string:

%%[
set @myCount = 0
set @totalProducts = 4
]%%
%%[ FOR @myCount = 1 TO @totalProducts DO ]%%
       %%[
        set @productTitle = Concat(@product,@myCount)
        ]%%
            <h1>%%=v(@productTitle)=%%</h1> 

%%[ NEXT ]%% 

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.