开发者

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 symbol开发者_运维百科izer = 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.


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"


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜