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

webmaster@zope.org webmaster@zope.org
Fri, 27 Sep 2002 15:10:31 -0400

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


      If the *updateInfo* script requires parameters, you must either
      choose a name for the DTML namespace binding (see Binding
      Variables below) so that the parameters will be looked up in the
      namespace, or you must pass the parameters in an expression,
      like this::

        <dtml-call expr="updateInfo(color='brown', pattern='spotted')">

        % Anonymous User - Sep. 4, 2002 12:34 pm:
         Calling a script with hardcoded values is pretty useless in the real world. It would be great to have an
         example that shows how to grab variables from the namespace and insert them into the parameter list in this

        % Anonymous User - Sep. 20, 2002 7:08 am:
         I'm not sure if the following snippet does the job:

         <dtml-call expr="updateInfo(color='<dtml-var hair_color>', pattern='<dtml-var hair_pattern>')">

        % Anonymous User - Sep. 26, 2002 5:27 pm:
         This does work:

         <dtml-var expr="make_user_list(users, abs_url)">
         <dtml-call expr="make_user_list(users, abs_url)">
         where users is a sql "dtml-in" call result parameter.
         abs_url was created like this:
         <dtml-set abs_url=absolute_url>

         in the above example, anything within the "" will be evaluated, so there is no need to specify "dtml-var".
         With sql calls this generally works:
         <dtml-in expr="some_sql_method(color=_['hair_color'], pattern=_['hair_pattern'])

        % Anonymous User - Sep. 26, 2002 5:29 pm:
         also, the parameters are grabbed from the context where the method was called.
         So, anywhere that <dtml-var hair_color> is valid, you can call a method that expects a hair_color parameter
         just with its name:
         <dtml-call some_method> and it will find the parameters.

        % Anonymous User - Sep. 26, 2002 6:14 pm:
         remember, in <dtml-call expr="..."> the expr will be evaluated in the _-namespace,
         which already contains all the variables for the arguments.
         <dtml-call expr="updateInfo(color='brown', pattern='spotted')">
         will do if _ contains variables "brown" and "spotted". blf

        % Anonymous User - Sep. 26, 2002 6:17 pm:
         ouch. "'brown'" and "'spotted'" in the given example are strings;
         <dtml-call expr="updateInfo(color=brown, pattern=spotted)"> would work w variables.

        % Anonymous User - Sep. 27, 2002 3:10 pm:
         "Binding Variables" again a forward reference. blf