Print variable value inside an html string in Velocity

2.8k Views Asked by At

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?

1

There are 1 best solutions below

0
Daniele Baggio On BEST ANSWER

the right sintax for Velocity is

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