3

I am using mako templates in pyramid which uses the ${} construct for variable substitution. I also use an Openlayers script to show a map with features. I want to style my features with Stylemap like so:

var symbolizer = OpenLayers.Util.applyDefaults(
    {externalGraphic: "images/${thumbnail}.png", pointRadius: 20},
    OpenLayers.Feature.Vector.style["default"]);
var styleMap = new OpenLayers.StyleMap({"default": symbolizer, "select": {pointRadius: 30}});
var vectorLayer = new OpenLayers.Layer.Vector("thumbs", {styleMap: styleMap});
...
vectorLayer.features[0].attributes.thumbnail="sight";
vectorLayer.features[1].attributes.thumbnail="bar";

See also The OpenLayers Styles Framework.

The problem I have is that mako interprets the Openlayers ${} variable as its own variable and I get a "NameError: Undefined" from the server. I have searched a while but could not find a solution.

Adrian
  • 33
  • 3

2 Answers2

4

The most concise solution I found was this:

  • "images/$${}{thumbnail}.png"

For completeness, the ones in the post mentioned by tonio are:

  • "images/<%text>${thumbnail}.png"
  • "images/${"$"}{thumbnail}.png"
user1372408
  • 426
  • 1
  • 4
  • 10
0

As far as I remember, you can use a double dollar sign to escape it:

"images/$${thumbnail}.png"

HTH,

EDIT: Huh, seems I was wrong, see https://groups.google.com/forum/#!topic/mako-discuss/g00Qq3_FNgg

tonio
  • 2,376
  • 1
  • 22
  • 28
  • Thanks tonio, it is a bit awkward but this works: {externalGraphic: <%text>"images/${thumbnail}.png"%text>, pointRadius: 20}. However the $${} does not work. Still interested if someone knows a nicer solution though. – Adrian May 18 '11 at 14:20