>我有一个静态主题,其中包含一些用于自定义jquery插件的json属性,例如
data-plugin-options='{"directionNav":false, "animation":"slide", "slideshow": false, "maxVisibleItems": 6}'
重氮编译器抱怨这个像
Invalid expression [0:0]
compilation error, element 'div' [400:0]
Attribute 'data-plugin-options': Failed to compile the expression ''directionNav':false, 'animation':'slide', 'slideshow': false, 'maxVisibleItems': 6' in the AVT. [0:0]
Invalid expression [0:0]
compilation error, element 'div' [445:0]
Attribute 'data-plugin-options': Failed to compile the expression ''directionNav':false, 'animation':'slide'' in the AVT. [0:0]
Invalid expression [0:0]
compilation error, element 'div' [512:0]
Attribute 'data-plugin-options': Failed to compile the expression ''controlNav':false, 'slideshow': false, 'animationLoop': true, 'animation':'slide'' in the AVT. [0:0]
并破坏渲染。
有没有办法使这项工作(除了将 conf 移动到 js(?
唯一的解决方案 - 这实际上是有意义的 - 是将参数拆分为多个data
属性。喜欢:
data-plugin-directionNav="false"
data-plugin-animation="slide"
data-plugin-slideshow="false"
data-plugin-maxVisibleItems="6"
这些是 TALES 表达式。尝试从"string:"开始。如果使用"$"和";",则需要对其进行转义。
查看 PyPI 上的 plone.app.themeing 页面;搜索"右手边是 TALES 表达式"以获取涵盖此内容的文档部分。
括号必须转义,即 {{
和}}
否则,xslt引擎将尝试评估/编译AVT中的表达式。
此外,属性值必须括在双引号中"
..."
和单引号中的字典值'
...'
如下所示:
attributename="{{xyz:'abc'}}"
这将转换为
attributename="{xyz:'abc'}"
请记住:当您加载没有重氮的 html 模板时(即直接从您的文件系统(,您一定不能转义大括号。否则,您的插件最终不会将其视为 json 字符串。