[ZPT] (no subject)

daniel.a.fulton@delphiauto.com daniel.a.fulton@delphiauto.com
Thu, 14 Jun 2001 18:59:19 +0800


If this is already answered, I apologize. I only get digest mode.

If I understand your question correctly, you're wanting to replace portions of
your ZPT / template macro depending on the variables passed in.  I assume an
http post or a form that actions a python script.

You might want to take a look at below message Evan posted:

http://mail.zope.org/pipermail/zpt/2001-May/001399.html

Here's a sample where I do this, I only replace 'msg' in this particular
instance but I think you get the jist.  The key is the options dict described in
Evan's mail.

<span tal:define="msg options/msg | default"
      tal:content="msg">

The below example is the password_form form and change_password method from the
CMF re-written in ZPT and Python Scripts.

--------------
password_form
--------------

<html metal:use-macro="here/hr_template/macros/master">
  <div metal:fill-slot="main">
     <form action="change_password" method="post">
<h3>Change Password</h3>
<font color="red">Note:  This changes your password for all internet / intranet
services</font>
<br><br>
<table class="FormLayout">
<tr>
<th>
<span tal:define="global msg options/msg | here/msg | default"
      tal:content="msg">
                 </span>
</th>
</tr>
<tr>
<th>Username
</th>
<td tal:define="member user"
    tal:content="member">Member
</td>
</tr>
<tr>
<th>New password
</th>
<td><input type="password" name="password">
</td>
</tr>
<tr>
<th>Confirm new password
</th>
<td><input type="password" name="confirm">
</td>
</tr>
<tr>
<th>Domains
</th>
<td>
<input type="text" name="domains:tokens" value=""><br>
<em> If you do not know what this field is for, leave it blank. </em>
</td>
</tr>
<tr>
<td><br></td>
<td><input type="submit" value=" Change ">
</td>
</tr>
</table>
</form>
</div>
</html>

-----------------
change_password
-----------------

failMessage = context.portal_registration.testPasswordValidity(password,
confirm)

if failMessage:

   return failMessage

else:

   context.portal_registration.setPassword(password, domains=None)
   context.portal_membership.credentialsChanged(password)
   msg = 'Password Changed'

   return context.password_form(msg=msg)


Regards,

Daniel

>Message: 5
>Date: Wed, 13 Jun 2001 01:16:17 -0500
>From: Lynn Walton <waltonl@franklin.edu>
>To: zpt@zope.org
>Subject: [ZPT] How to call a python script ...
>
>Can someone show me how I could achieve the following?
>
>I'm thinking I might wish to have in a master template (macro defined on
>html tag)  make a call to a python script which will generate a massive
>amount of
>html code which needs to be dependent on 3 variables passed into the
>script.

>
>MasterTemplate  contains call to script that yields complicated html
>that varies based on some values passed in.
>PageTemplates which use the main macro defined in the html tag of
>MasterTemplate declare/set the values that I need to have passed in the
>script ... presumably by putting something like  <div tal:define="global
>someValue string:Fred"></div>  in the top of the page.
>How does the call to the script look in the MasterTemplate  AND how
>does the script retrieve the value of someValue set in the page
>template?

>Thanks,
>Lynn