I don't know if Sunil Kumars answer answered the problem for the topic starter? I have the same issue, and I know how to add the image to the page, but it is the test whether there is an image which does not work.
I've changed the template to
<a href="[=URL]" target="[=TARGET]"><img src="[=ICON]" height="20"> [=TEXT]</a>
Which works, except that it always includes an image tag, even if there is no icon. That might be visually correct, until you apply styling to the image (like the margin you likely want between the image and the text)
So, just like the topic starter, I added the test [?ICON], but this seems to always evaluate to 'false'. (and [?!ICON] always evalueates to 'true')
Even weirder: I had a space after the (end of the) if statement, but then there is no space in the output. I guess somebody decided to trim whitespace after the tokens to allow for nicer markup, even though whitespace does have some significance. moving the space inside the if and else blocks fixed this.
<a href="[=URL]" target="[=TARGET]">[?ICON]<img src="[=ICON]" height="20"> [?ELSE]- [/?][=TEXT]</a>
is not equal to
<a href="[=URL]" target="[=TARGET]">[?ICON]<img src="[=ICON]" height="20">[?ELSE]-[/?] [=TEXT]</a>
and neither of them work :'(