[Zope] How to write a method using DTML Method?

Chris McDonough chrism@digicool.com
Tue, 11 Jan 2000 16:21:35 -0500


Let's try it in Python.  We can do it in DTML, but it just looks so much
*nicer* in Python.

def getFirstName(name):
    import string
    lastName=string.split(name, " ")[1]
    return lastName

You can create an External Method that contains this code and it'll do
what its Java counterpart does when you call it from DTML or from
Python.

To call it, we'd do something like this in DTML where
listofUniqueFullNames is a SQL method that returns "SELECT DISTINCT
FULL_NAME FROM NAMES", which returns a recordset object that contains an
attribute FULL_NAMES which is a tuple of strings like ("John Smith",
"Uncle Sam", )

<dtml-in listOfUniqueFullNames>
  <dtml-var "getFirstName(FULL_NAME)">
</dtml-in>
    
This will return to a client browser:

Smith
Sam

Guy Davis wrote:
> 
> How would I convert the following Java code into DTML?  This is just an
> example, I don't understand how methods are used in DTML.
> 
> String getFirstName(String name) {
>    String lastName = name.substring(0, name.indexOf(' '));
>    return (lastName);
> }
> 
> I would like to see a DTML method which does this, how it is called and
> how the result is used in the calling method.  Thanks.
> --
>        Guy Davis    mailto:davis@arc.ab.ca
>   (403) 210-5334    Alberta Research Council
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )

-- 
Chris McDonough - Digital Creations, Inc.
Publishers of Zope - http://www.zope.org