Basic if statement in transformation

Alan Isaacson asked on October 14, 2015 14:19

I have a transformation that I want to use to display arrow overlays on another image. I currently have the code below that picks up the X & Y co-ordinates as expected:

  <img id="arrow_2" name="dynamic" style="position:absolute; left:{% IllustrationXCoOrdinates1 %}px; top:{% IllustrationYCoOrdinates1 %}px; width:32px; height:32px;" src="http://www.vetstream.com/images-canis/7_30283.gif" width="32" height="32"/>
  <img id="arrow_2" name="dynamic" style="position:absolute; left:{% IllustrationXCoOrdinates2 %}px; top:{% IllustrationYCoOrdinates2 %}px; width:32px; height:32px;" src="http://www.vetstream.com/images-canis/7_30283.gif" width="32" height="32"/>

However not all bullet points have co-ordinates, so I would like to say If IllustrationXCoOrdinates1 contains data then <img id="arrow_2" name="dynamic" style="position:absolute; left:{% IllustrationXCoOrdinates1 %}px; top:{% IllustrationYCoOrdinates1 %}px; width:32px; height:32px;" src="http://www.vetstream.com/images-canis/7_30283.gif" width="32" height="32"/>

Any help appreciated as still quite new to all of this.

Correct Answer

Jan Hermann answered on October 14, 2015 15:50

Hi,

try this if -> (IllustrationXCoOrdinates2.ToString() != "") -> it converts null values to an empty string and then the statement matches.

Best regards,
Jan Hermann

0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on October 14, 2015 14:30

Check out the Macro Syntax documentation, specifically the Conditional statements section. This should get you the logic you need.

0 votesVote for this answer Mark as a Correct answer

Alan Isaacson answered on October 14, 2015 14:32 (last edited on October 14, 2015 14:33)

Thanks Brenden, I had been looking at that and seem to have confused myself even more. I will carry on playing some samples.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on October 14, 2015 14:43 (last edited on October 14, 2015 14:45)

Here's an example:

{% if (IllustrationXCoOrdinates1 != "") {"<img id='arrow_2' name='dynamic' style='position:absolute; left:" + IllustrationXCoOrdinates1 + "px; top:" + IllustrationYCoOrdinates1 + "px; width:32px; height:32px;' src='http://www.vetstream.com/images-canis/7_30283.gif' width='32' height='32'/>"} %}
0 votesVote for this answer Mark as a Correct answer

Alan Isaacson answered on October 14, 2015 14:55

Hi Brenden, That appears to stop the line of code so in the source of the page I only get

px; top:px; width:32px; height:32px;' src='http://www.vetstream.com/images-canis/7_30283.gif' width='32' height='32'/>"} %}

My transformation lines now read as

{% if (IllustrationXCoOrdinates1 != "") {"<img id='arrow_2' name='dynamic' style='position:absolute; left:{% IllustrationXCoOrdinates1 %}px; top:{% IllustrationYCoOrdinates1 %}px; width:32px; height:32px;' src='http://www.vetstream.com/images-canis/7_30283.gif' width='32' height='32'/>"} %}

{% if (IllustrationXCoOrdinates2 != "") {"<img id='arrow_2' name='dynamic' style='position:absolute; left:{% IllustrationXCoOrdinates2 %}px; top:{% IllustrationYCoOrdinates2 %}px; width:32px; height:32px;' src='http://www.vetstream.com/images-canis/7_30283.gif' width='32' height='32'/>"} %}  
0 votesVote for this answer Mark as a Correct answer

Alan Isaacson answered on October 14, 2015 15:01

It appears that it is simply the inner part of the code I need to nest somehow around the top:{% IllustrationYCoOrdinates1 %}px; I have tried (IllustrationYCoOrdinates1) but it doesn't translate to the field content.

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on October 14, 2015 15:14

Alan, if you remove your inner macro containers "{% %}" and have all of it wrapped in one, then it should work.

{% if (IllustrationXCoOrdinates2 != "") {"<img id='arrow_2' name='dynamic' style='position:absolute; left:" + IllustrationXCoOrdinates2 + "px; top:" + IllustrationYCoOrdinates2 + "px; width:32px; height:32px;' src='http://www.vetstream.com/images-canis/7_30283.gif' width='32' height='32'/>"} %}

0 votesVote for this answer Mark as a Correct answer

Alan Isaacson answered on October 14, 2015 15:29

Many thanks Joshua that makes sense.

0 votesVote for this answer Mark as a Correct answer

Alan Isaacson answered on October 14, 2015 15:40

Just realised that if the field is empty it still writes the remainder of the code to the page so the source code gives me <img id='arrow_2' name='dynamic' style='position:absolute; left:px; top:px; width:32px; height:32px;' src='http://www.vetstream.com/images-canis/7_30283.gif' width='32' height='32'/>

0 votesVote for this answer Mark as a Correct answer

Alan Isaacson answered on October 14, 2015 15:56

Excellent, that looks a lot better. Now I can start working out what co-ordinates to use.

0 votesVote for this answer Mark as a Correct answer

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