Diazo theme with json attributes error: "Attribute 'data-plugin-options': Failed to compile the expression"

StackOverflow https://stackoverflow.com/questions/18492482

Question

I have a static theme that contains some json attributes for customizing jquery plugins, like

data-plugin-options='{"directionNav":false, "animation":"slide", "slideshow": false, "maxVisibleItems": 6}'

diazo compiler complains about this like

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]

and breaks the rendering.

Is there a way for making this work (beside moving the conf to js)?

Was it helpful?

Solution

It seems the only solution - and that actually make sense - is to split the parameters in more than one data attribute. Like:

data-plugin-directionNav="false"
data-plugin-animation="slide"
data-plugin-slideshow="false"
data-plugin-maxVisibleItems="6"

OTHER TIPS

These are TALES expressions. Try starting with 'string:'. You'll need to escape '$' and ';' if you use them.

Check the plone.app.theming page on PyPI; search for "The right hand side is a TALES expression" for the documentation section covering this.

Braces must be escaped, i.e. {{ and }} otherwise the xslt-engine will try to eval/compile the expressin in the AVT.

Furthermore, the attribute value must be enclosed in double quotes "..." and the dict values in single quotes '...' like the following:

attributename="{{xyz:'abc'}}"

this will transform into

attributename="{xyz:'abc'}"

Remember: when you load the html-template without diazo (i.e. directly from your filesystem) you must not escape the braces. Otherwise your plugin eventually will not treat it as a json-string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top