liferayliferay-velocity

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?


Solution

  • the right sintax for Velocity is

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