Sunit Joshi Sunit Joshi - 3 months ago 19
Jade Question

Jade variable interpolation

I'm trying to interpolate jade variable in an image source and it doesn't seem to be working. Normal p tags work though!

- var lat=34.768464;
- var long=-86.346556

- var mapUrl = "http://maps.googleapis.com/maps/api/staticmap?center=#{lat},#{long}&zoom=17&size=400x350&sensor=false";

p Latitude: #{lat}, Longitude: #{long}

img(src="#{mapUrl}")


I run it in cmd line and get this output:

<img src="http://maps.googleapis.com/maps/api/staticmap?center=#{lat},#{long}&amp;zoom=17&amp;size=400x350&amp;sensor=false">


Jade HTML

Any ideas what I'm doing wrong here ?

thanks
SJ

Answer

Variable interpolation doesn't work that way, you want:

var mapUrl = "http://maps.googleapis.com/maps/api/staticmap?center="+lat+","+long+"&zoom=17&size=400x350&sensor=false";

You want to concatenate the two strings in Jade's JS runtime, not in the page url.