How to write if else condition in transformation

raj k asked on November 19, 2014 10:30

How to write if else condition in transformation

Correct Answer

Jan Hermann answered on November 19, 2014 14:47

It depends on the transformation type. For most of them (like Text/XML) you can simply use this one:

{%
if (...) {
...
}
else {
...
}
%}

However, if you use ASCX transformations, you need to use IfCompare method:

<%# IfCompare(1, 2, "The values are different", "The values are equal") %>

Best regards,
Jan Hermann

0 votesVote for this answer Unmark Correct answer

Recent Answers


Vilém Jeniš answered on November 20, 2014 16:19 (last edited on November 20, 2014 16:19)

I would also suggest this forum thread: http://devnet.kentico.com/forums?forumid=65&threadid=40763.

I find the idea of writing placeholders with visibility conditions quite heplful and used it myself. It's a great way of mimicking the function of this:

{%
if (...) {
    ...
}
else {
    ...
}
%}

when you really need ASCX transformations.

In short, this approach can be useful, when conditions in transformations get complicated:

<asp:Placeholder runat="server" ID="pl1" visible='<%# ... %>'> 
    ...
</asp:Placeholder>
<asp:Placeholder runat="server" ID="pl2" visible='<%# !pl1.Visible %>'> 
    ...
</asp:Placeholder>
0 votesVote for this answer Mark as a Correct answer

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