Frage

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.

War es hilfreich?

Lösung

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

Andere Tipps

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"
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top