ZPT-JS reference - Attributes - TALDefine

Syntax

argument       ::= define_scope [';' define_scope]*
define_scope   ::= ('global') ('nocall') define_var
define_var     ::= variable_name expression
variable_name  ::= Name
                

Description

The data-define statement defines variables.

You can define two different kinds of TAL variables: local and global. When you define a local variable in a statement element, you can only use that variable in that element and the elements it contains. If you redefine a local variable in a contained element, the new definition hides the outer element’s definition within the inner element. When you define a global variable, you can use it in any element processed after the defining element. If you redefine a global variable, you replace its definition for the rest of the template. Local variables are the default.

Nocall definitions avoid rendering the results of a path expression. An ordinary path expression tries to render the object that it fetches. This means that if the object is a function, method or some other kind of executable thing, then expression will evaluate to the result of calling the object. This is usually what you want, but not always. For example, if you want to put a function into a variable so that you can refer to invoke it, you can’t use a normal definition (non nocall) because it will invoke the function only once (at the data-define).

Note: extracted from Zope Page Templates Reference.

Differences with ZPT

Examples

Defining a global variable:

data-define="global companyName 'Zope Corp, Inc.'"
                

Defining two local variables, where the second depends on the first:

data-define="myTitle myObject/title; 
              tlen myTitle/length"
                

Defining a nocall variable:

data-define="nocall myFunction myObject/myFunction()"
                

Note: some parts extracted from Zope Page Templates Reference.