Freemarker (Responsys RPL variant) Interpret & exec a key/value pair from a table

248 views Asked by At

I'm reading a key/value pair from a table which is denoted as such:

fruit:${my_fruit} in the FOOD column.

In my Freemarker code, I have, say:

<#assign my_fruit = "banana">

I want to wind up with the equivalent of

<#assign fruit = ${my_fruit}> executed.

I've tried many variations of

<#fruit_list = "${FOOD}"!?split(":")>

<#assign fruit_raw = r"<#assign " + "${fruit_list[0]}" + r"='" + "${fruit_list[1]}" + r"'>">

<#assign fruit_int = fruit_raw?interpret>

<@fruit_int?exec/>

Can anyone tell me where I'm going wrong? Many thanks.

2

There are 2 answers

3
ikonoklast On

This seems to work:

<#if fruit_list[0]?? && fruit_list[1]??>
<#assign fruit_txt = "<#assign ${fruit_list[0]} = '${fruit_list[1]}'>">
<#assign fruit_raw = 'r"${fruit_txt}"?exec'>
<@fruit_raw?interpret/>
</#if>
0
John Lillard On

Based on the simplicity of your question <#assign fruit=my_fruit> will work in Responsys. I'm guessing though that you're looking for something more complicated? enter image description here