[ZDP] BackTalk to Document The Zope Book (2.5 Edition)/Advanced Page Templates

webmaster@zope.org webmaster@zope.org
Wed, 25 Sep 2002 19:27:20 -0400


A comment to the paragraph below was recently added via http://www.zope.org/Documentation/Books/ZopeBook/current/AdvZPT.stx#3-17

---------------

      You can define as many variables as you wish. Each variable can
      have its own global or local scope. You can also refer to
      earlier defined variables in later definitions. For example::

        <p tal:define="title template/title;
                       tlen python:len(title);">

        % Anonymous User - Sep. 25, 2002 7:27 pm:
         The *scope of a variable* is the *space in a program text*, where the variable is visible = accessible by its
         name; for different variables with the same name and nested scopes as usual the inner variable takes
         precedence, thus occluding the outer one.
         The *lifetime* of a variable is the *time during execution* where this variable exists.

         By default, the lifetime of a variable is *local*, ie. the HTML tag where it is defined. 
         A "global" variable exists from its defining HTML tag to the end of the template.
         A "local" variable exists only in its defining HTML tag. 

         A *global* variable may be *redefined* by another global definition later in the template. (strictly, it
         ceases to exist while another one with the same name is created).
         A global variable may be *occluded* by the definition of a local variable later in the template. 
         A *local* variable may be *occluded* by another local variable in an inner HTML tag. 
         A local variable may be occluded by a global variable defined in an inner HTML tag from the defining HTML tag
         (of the global) for the remainder of the outer local variable. In this case, the inner (local) variables
         lifetime is limited by its defining HTML tag, whereas the global variable exists until the end of the
         template. It is like the lokal variable is redefined and promoted to global at the same time.
         if i err, explain. blf.