[ZPT] An easier question ...

Steve Spicklemire steve@spvi.com
Thu, 31 May 2001 06:15:47 -0500


Hi Lynn,

	We're practically neighbors! I work at the University of Indianapolis.

On Thursday, May 31, 2001, at 02:10 AM, Lynn Walton wrote:

> If I have  a master template like the example master_page and another PT
> (like the use_master example) that uses the main macro in the
> master_page, can I set/define a variable to a value in the use_master
> that the master_page "looks for" with a tal:condition statement  to
> determine if to do something?
>
> If so how would I do it.  What would setting the variable to a value in
> the uses_page look like, and what would the tal:condition look like? I'm
> confused on here/...  vs  template/...  vs some other way?  etc.

> I tried
> <span tal:define="global myVar string:myString"></span>  in the
> use_master page
> but nothing I put in the master_page  seems to "get it".  I've tried
> things like
>   tal:condition="python: template.myVar == 'the string I want to
> compare'"
>   tal:condition="python: here.myVar == 'the string I want to compare'"
>

This works for me:

master_page:

<html metal:define-macro="page">
   <head>
     <title tal:content="template/title">The title</title>
   </head>
   <body metal:define-slot="body">
     This is Page Template <span tal:replace="template/title" />.
     <p metal:define-macro="para">Plug some text in
       <span metal:define-slot="text">here</span>.
     </p>
     <p metal:define-macro="condPara">
     	<span><span tal:condition="myTest">My TestResult</span>
     	   <span metal:define-slot="text">this is from master..
     	   </span>
     	</span>
     </p>
   </body>
</html>

slave:

<html metal:use-macro="here/master_page/macros/page">
   <head>
     <title tal:content="template/title">The title</title>
   </head>
   <body metal:fill-slot="body">
     Totally Different Text.
    <div tal:define="theInput request/theInput | default;
                     myTest python:theInput == 'hello?'">
        <pre>
        The input = '<span tal:replace="python:theInput">theInput</span>'
        MyTest = '<span tal:replace="python:myTest">myTest</span>'
        </pre>
     <p metal:use-macro="here/master_page/macros/para">Plug some text in
       <span metal:fill-slot="text">this slot</span>.
     </p>
     <p metal:use-macro="here/master_page/macros/condPara">
     	<span tal:condition="python:myTest">
     	   <span metal:fill-slot="text">Should only show if theInput is 
'hello?'.</span>
     	</span>
     </p>
    </div>

   </body>
</html>


> Also,  for me, here/title is always evaluating to nothing, even when I
> have the title property set on both the master_page and uses_page (to
> two different values).   Should it give me the title from master_page or
> use_master page if I'm viewing use_master ?  It gives neither, so I'm
> confused.
> If master_page has template/title it gives me the one in the use_master
> template if that's what I'm viewing.  But shouldn't here/title work too?
> If not, can someone explain to me when/how here works?
>
> I know the spec says here is the object to which the template is being
> applied.  But if I were viewing use_master wouldn't use_master be the
> obect to which the master_page is being applied?  So in that context,
> shouldn't here/title and template/title be the same?
>

I think 'here' is the folder that the template is in.

> Thanks,
> Lynn
>
>

And then this..

> Hello,
>
> I'm new to zope and zpt.  I've decided to use zope for a new website
> rollout at the University where I'm employed.
> Although I think dtml looks easier to understand (and has better
> documentation) I'm inclined to think ZPT is a better way to go, worth
> the investment to learn. Of course I'm a little concerned about whether
> it's ready enough for production but we probably won't get to production
> for a couple more months.
>
> First let me say thanks to Evan for all his work on this project.  Keep
> that documentation coming! <g>
> And thanks to Peter B, for the many examples and docs you've provided so
> far.
>
> Two things now.
> 1) When I import the zpt_examples into the root folder on my zope
> installation and try the batch example, the link for the Next 3 doesn't
> seem to work.  It takes me to my root directory's index.html (which in
> my case is still the default zope quick start screen).   Is this a bug
> or am I not understanding it?

hmmm.. it works for me....

> 2) Although we intend to get into content management aspects, and other
> powerful zope features later, the first thing I need to do to get my
> team working is to be able to provide our standard look and feel so that
> we can start making our "static" like pages (ones that aren't data or
> logic dependent that is).  Our standard look & feel would include the
> html, head (where we want to be able to insert different javascripts in
> different pages) body, opening table, tr, td with our left hand
> navigation, td that would represent the area that different in each page
> so I would imagine this would be a define-slot in the master template,
> then all the appropriate closing tags.
>
> Two questions I have ... is there a way to do something like this from
> http://www.zope.org/Members/Caseman/client_script_howto
>
> Next, we modify our friend and ally standard_html_header so that it
> inserts scripts for any documents that request them. Simply insert the
> DTML code below within the <HEAD> section of your standard_html_header.
>
>                           <dtml-if scripts>
>                               <dtml-comment>
>                                    Include Java Scripts Specified by
> Scripts Property
>                               </dtml-comment>
>                               <META HTTP-EQUIV="Content-Script-Type"
> CONTENT="text/javascript">
>                               <SCRIPT language="JavaScript"><!--
>                               <dtml-with java_script>
>                                   <dtml-in scripts>
>                                       //
>                                       // Script of <dtml-var
> sequence-item>
>                                       //
>                                       <dtml-var
> "_.getitem(_['sequence-item'],1)">
>                                   </dtml-in>
>                               </dtml-with>
>                               //--></SCRIPT>
>                           </dtml-if scripts>
>
> but in a master template?

I'll try to take a stab at converting this to ZPT as a learning 
exercise. ;-)

2) Can someone show me a simple example of how I would be able to have a
> variable in each different page that is using the master template, tell
> it which of the menu items (that are in the left hand navigation menu
> contained in the master template ) to "highlight" where in this case by
> "highlight" I mean just change in some "look and feel" way ... be it
> adding a graphic next to it, changing the text font color, etc.

I think this is basically your earlier question... if not let me know!

> Or maybe a variable in each page isn't the way to do it ... ? I don't
> know if a property for that document would be better?  But I would guess
> that all the menu's would have to have some condition check to determine
> if it's the one that is supposed to be highlighted.
>
> All help greatly appreciated.
>
> Thanks,
> Lynn
>
>
>
>
>
>
>
>
>
> _______________________________________________
> ZPT mailing list
> ZPT@zope.org
> http://lists.zope.org/mailman/listinfo/zpt