Syntax
argument ::= (attribute_simple_statement | attribute_map_statement) [';' (attribute_simple_statement | attribute_map_statement) ]* attribute_simple_statement ::= attribute_name expression attribute_name ::= Name attribute_map_statement ::= Name
Description
The data-attributes statement replaces the value of an attribute (or creates an attribute) with a dynamic value. The value of each expression is converted to a string, if necessary.
If the expression associated with an attribute assignment evaluates to undefined
, then that attribute is deleted from the statement element. Each attribute assignment is independent, so attributes may be assigned in the same statement in which some attributes are deleted and others are left alone.
If you use data-attributes on an element with an active data-omit-tag or data-replace command, the data-attributes statement is ignored.
If you use data-attributes on an element with a data-repeat statement, the replacement is made on each repetition of the element, and the replacement expression is evaluated fresh for each repetition.
Note: extracted from Zope Page Templates Reference.
Differences with ZPT
The attribute_map_statement part is not present in ZPT.
Examples
Replacing a link:
<a href="/sample/link.html" data-attributes="href myObject/getUrl()"> My link </a>
Replacing two attributes:
<textarea data-attributes="rows textareaRows; cols textareaCols"> </textarea>
Replacing attributes using an attribute_map_statement:
<textarea data-attributes="textareaAttrs"> </textarea>
We must define an object as value for textareaAttrs in scope, for example using the dictionary:
var dictionary = { textareaAttrs: { rows: 10, cols: 100 } };
The resulting visible HTML is:
<textarea data-attributes="rows 10; cols 100"> </textarea>