Luca Detomi
Luca Detomi

Reputation: 5716

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?

Upvotes: 0

Views: 2890

Answers (1)

Daniele Baggio
Daniele Baggio

Reputation: 2257

the right sintax for Velocity is

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

Upvotes: 2

Related Questions