2

I'm facing an issue since yesterday. I wanted to test the fact that, within a FOR loop, i'm able to dynamically create variables for each link.

A quick example:

%%[

For @u = 1 to 10 do

Set @row = Row(@myArticlesArray, @u);
Set @myIndexArticle = Field(@row,1);
TreatAsContent(Concat("%","%[Set @articleLink",@u," = Replace(Replace(Field(Row(@links,@myIndexArticle),'Value'),'%2F','/'),'%3A',':')]%", "%"))

]%%

    <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff">
            <tr>
                <td><a href="%%=RedirectTo(??)=%%"">My Article Title</a></td>
            </tr>

    </table>        

%%[ Next @u ]%%

In that particular case, I check for urls in an xml feed, decode it to replace the special characters (and have a proper ://, instead of a %3A%2F%2F).

This first step works perfectly. I end up with 10 variables named @articleLink1, @articleLink2.... @articleLink10.

But what do I have to put on the "href" parameter to refer to it? I tried many things, with Concat, TreatAsContent and more, but nothing seems to work.

Thank you in advance!

P.S The loop until 10 is an exemple, I can have more or less articles.

1 Answer 1

2

I had to hard-code some "test" values since I don't have access to @myArticlesArray, but this appears to work (you should be able to uncomment/restore your original code, accordingly):

Also note, this may require the use of httpgetwrap|; see: https://salesforce.stackexchange.com/a/70736/55245

%%[
For @u = 1 to 10 do

  Set @row = Row(@myArticlesArray, @u)
  /*Set @myIndexArticle = Field(@row,1)*/
  Set @test = Concat('https://example.com/?q=', @u)

/* @test substitutes...
 *
 * Field(Row(@links,@myIndexArticle),'Value')
 *
 * ...in the below TreatAsContent() for the sake of testing
 */
]%%
%%=TreatAsContent(
  Concat(
    '%',
    '%[Set @articleLink',
    @u,
    ' = Replace(Replace(@test, "%2F", "/"), "%3A", ":")]%',
    '%'
  )
)=%%

<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff">
  <tr>
    <td><a %%=TreatAsContent(Concat('href="%', '%[Output(v(@articleLink', @u, '))]%', '%"'))=%%>My Article Title</a></td>
  </tr>
</table>        

%%[
Next @u
]%%
1
  • Indeed, that what i was looking for!
    – G. Martin
    Apr 9, 2019 at 8:37

You must log in to answer this question.

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