Adrian
Adrian

Reputation: 33

variable substitution conflict between mako and Openlayers

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.

Upvotes: 3

Views: 1021

Answers (2)

user1372408
user1372408

Reputation: 436

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"

Upvotes: 4

tonio
tonio

Reputation: 2376

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

Upvotes: 0

Related Questions