0

I have created a Liferay Web Content Structure and Template. This Structure contains an image that can or can not be set. If the image is not set then I do not want to render an IMG tag.

How can I determine in my template if the picture is set / present ?

Best regards,

Daniel

Breiti
  • 579
  • 5
  • 21

2 Answers2

1

If your field is called imageField you can do it like this with Velocity:

#if ($imageField.data != "")
  <img src="$imageField.data">
#end

(For Freemarker you can do a similar test)

Tobias Liefke
  • 8,637
  • 2
  • 41
  • 58
1

Following the answer of Tobias, you could also use the $validator.isNull() from velocity for null / not null value(s).

Sample code snippet:

#if (!$validator.isNull($imageField.data) && $imageField.data != "")
  <img src="$imageField.data">
#end

HTH

Parkash Kumar
  • 4,710
  • 3
  • 23
  • 39
Jorge
  • 141
  • 8