using an IF statement to display content in a transformation.

Kim Tompkins asked on April 10, 2021 00:47

I want to display different content based on the value of the custom field Section1CoulnCount. I have the transformation set up as Text/XML but I have also tried ASCX. this is what I'm starting with. something very simple just to see if I can get it to work. I can't :)

Section1ColumnCount is text value attached to a radio button that will either be equal to 1 or 2

<%# If(Eval(Section1ColumnCount.Value) == 2,"<div><p>Yes</p>","<div><p>No</p></div>") %>

thank you for all the help as I learn 

Correct Answer

Brenden Kehren answered on April 10, 2021 01:18

You're mixing macro syntax with ASCX syntax. Change your transformation type to ASCX and use this syntax:

<%# If(Eval<int>("Section1ColumnCount") == 2,"<div><p>Yes</p>","<div><p>No</p></div>") %>

2 votesVote for this answer Unmark Correct answer

Recent Answers


Kim Tompkins answered on April 12, 2021 17:41

Thank you I will try this. For my knowledge Is there a way to do this using macro syntax?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on April 12, 2021 19:15

You can use the following macro to do the same thing. You need to make sure your transformation is a Text/HTML transformation type. Macro syntax is very similar to C#.

{% if(Section1ColumnCount == 2) { "<div><p>Yes</p>" } else { "<div><p>No</p></div>" } %}

0 votesVote for this answer Mark as a Correct answer

Kim Tompkins answered on April 12, 2021 19:48

Thank you!

0 votesVote for this answer Mark as a Correct answer

Kim Tompkins answered on April 12, 2021 21:50

Just one more question please. the last part of this is that now that I have the syntax of the IF statement I would like to replace the "Yes" and "No" with a form field. Can you direct me to a good reference for macro syntax?

{% if(Section1ColumnCount == 2) { "<div><p>"{% Section1_LeftSide%}"</p>" } else { "<div><p>No</p></div>" } %}
0 votesVote for this answer Mark as a Correct answer

Kim Tompkins answered on April 12, 2021 22:14 (last edited on April 12, 2021 22:15)

I did find the answer to my last question. I will post it here in case anybody else comes across this with the same questions. Thank you for the help. DevNet has been very helpful to me.

 {% if(Section1ColumnCount == 2){ %}
<div><p>{%Section1_LeftSide%}</p></div>
{% } else { %}
<div><p>{%Section1_RightSide%}</p></div>
{% }#%}
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.