简体   繁体   中英

Liferay Web Content Template : How to find out if image has been set?

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

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM