[Zope] [newbie] Property with <dtml-var> in it's value

Dieter Maurer dieter@handshake.de
Thu, 19 Apr 2001 20:03:47 +0200 (CEST)


Stefan Mallepell writes:
 > "A" is the object-instance with a
 >      property "l" which contains 'http://www.externalserver.org' and the id
 > 'externalserver'
 > "B" is another object-instance with a
 >      property "c" which contains 'This is text with some links. The links to
 > the *externalserver* can be in the middle of the text.'
 > 
 > In my index_html I show "c" an would like to generate a proper "a href"
 > around *externalserver* ...
You have 3 problems - all solvable:

 1. locate the ranges in "c" to be replaced by "a href=..."
 2. find the link for an id ("externalserver" in your example)
 3. insert the links into "c"


For 1. and 3. you would use Python's "re" module (regular expressions),
more precisly, the "sub" method (for "substitute"). You find documentation
on "re" in the Python library documentation (--> www.python.org).

As it is not too difficult to create long running regular expressions,
"re" was considered too dangerous to expose it to DTML or
Python Script. Thus, you will either need an External Method
or learn how to make additional modules accessible from
Python Script (--> searchable mailing list archives).

If you have an "id" and you want to get the corresponding
object, you can use "_.getitem(id)". Thus, if "id" contains
"externalserver", then "_.getitem(id).l" will be
equivalent to "externalserver.l", the "l" attribute of "externalserver".
This solves 2.

Dieter