On Tue, 11 Jul 2000, Jerome ALET wrote:
> ' and " are equivalent

Not quite true.  dtml only recognizes " for surrounding dtml expressions.
But you are right that they are equivalent in python.

> () are for functions or methods

To call functions or methods: blah(somearg).  But also used for
grouping in expressions: a * (b+c), and for delimiting immutable sequences:
('thing', 'secondthing').

> [] are for arrays (aka list, aka tables) or dictionnaries (aka mappings)

[] can be used to index into sequences: a[3], or to slice out a
portion of a sequence: a[2:4] (see the python guide for more).
Also key lookup out of dictionaries/mappings.  But to *define*
dictionaries you use {}:  {'key1': 'val1', 'key2': 'val2'}.

The most confusing part is the interface between dtml and python.
in an expr, inside the quotes you are in python and things follow
python syntax rules.  This gets really confusing when you have
dtml variables that have hyphens in them, since in python that's
the subtraction symbol.  So inside a python expression, you have
to look up such symbols in the dtml name space.  The dtlm namespace
is named '_', and is a mapping.  So you have things like:

<dtml-var expr="_['sequence-index']+1">

which prints out a number one greater than the current sequence-index.

You can leave off the 'expr=' above, and because of the "s, dtml
will assume it.  This is the way most dtml is written, with the
expr= or name= left out, and that can be very confusing when you
don't know the rules; see the dtml guide.

This is but the briefest introduction to this topic, but hopefully
it will make a few things clearer.


Zope maillist  -  [EMAIL PROTECTED]
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-dev )

Reply via email to