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

401 views Asked by At

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)?

3

There are 3 answers

0
simahawk On BEST ANSWER

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"
2
SteveM On

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.

0
wolfrevo On

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.