简体   繁体   中英

Print variable value inside an html string in Velocity

I need to append a suffix to an URL in Velocity (inside a Liferay template).

I have the following (simplified) code:

#set($isMobile = "")
<img src="http://www.example.com/icon-facebook$isMobile.png" >

#set($isMobile = "-mobile")
<img src="http://www.example.com/icon-facebook$isMobile.png" >

In my intention this should result in:

<img src="http://www.example.com/icon-facebook.png" >
<img src="http://www.example.com/icon-facebook-mobile.png" >

but instead I'm obtaining this (as variable is printed literally and not parsed)

<img src="http://www.example.com/icon-facebook$isMobile.png" >

Please, how to solve?

正确的速度正弦是

<img src="http://www.example.com/icon-facebook${isMobile}.png" >

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