If-then Statement in Text/XML Transformation Not Working

Andre Pfanz asked on March 15, 2016 19:10

I'm using a repeater that shows people's information, including their image with Text/XML transformation. Some people do not have photos, so I want to hide the image tag for them. I tried this:

{% if (Image != "")  { "<img class=\"img-responsive\" src=\"" + Image  + "\"/>" } else { } %}

Where Image is a file upload field. The problem is the image tag is always appearing - even for those whose value for Image is blank.

Does anyone know what I'm missing?

Correct Answer

Trevor Fayas answered on March 15, 2016 19:30

I often have to use the 'return' statement in the curly, may also want to use the string.IsNullOrWhiteSpace()

{% if (!string.IsNullOrWhiteSpace(Image)) { return "<img class=\"img-responsive\" src=\"" + Image + "\"/>" } |(identity)GlobalAdministrator%}

3 votesVote for this answer Unmark Correct answer

Recent Answers

Andre Pfanz answered on March 15, 2016 19:34

Thanks Trevor - that worked!

0 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on March 16, 2016 12:18

Hi Andre,

Though you have got an answer however, this should also work for you. It's good to have multiple syntax doing same work.

{% IfEmpty(Eval("Image"), <img class=\"img-responsive\" src=\"" + Image + "\"/>" : "") ) %}

Please mark this as a scorrect solution if this works for you.

Thanks, Chetan

1 votesVote for this answer Mark as a Correct answer

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