mako 和 Openlayers 之间的变量替换冲突
我在金字塔中使用 mako 模板,它使用 ${} 构造进行变量替换。我还使用 Openlayers 脚本来显示包含要素的地图。我想使用 Stylemap 来设计我的功能,如下所示:
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";
另请参阅OpenLayers 样式框架。
我遇到的问题是,mako 将 Openlayers ${} 变量解释为自己的变量,并且我从服务器收到“NameError:未定义”。我搜索了一段时间但找不到解决方案。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现的最简洁的解决方案是:
为了完整起见,tonio提到的帖子中的解决方案是:
The most concise solution I found was this:
For completeness, the ones in the post mentioned by tonio are:
据我记得,您可以使用双美元符号来转义它:
HTH,
编辑:呵呵,似乎我错了,请参阅 https://groups.google.com/forum/#!topic/mako-discuss/g00Qq3_FNgg
As far as I remember, you can use a double dollar sign to escape it:
HTH,
EDIT: Huh, seems I was wrong, see https://groups.google.com/forum/#!topic/mako-discuss/g00Qq3_FNgg