[ZPT] Reason for <script> and <style> exclusion?

Harry Wilkinson harryw@nipltd.com
Tue, 26 Mar 2002 17:11:08 +0000


> Got it. STYLE and SCRIPT tags don't contain XHTML data; therefore, they
> don't really fit the ZPT model of output. It would be possible to allow
> something like:
>
> <style>
>   <tal:block tal:condition="...something here..." tal:omit-tag="">
>     P { ... }
>   </tal:block>
> </style>
>
> So that you could output that P style only on a certain condition. It
> would be pretty ugly, though--all those meaningless blocks and
> omit-tags, etc.
>
> In any event, this isn't be allowed since ZPT ignores the content of
> these blocks.
>
> You could always handle the whole thing like this:
>
> <style>
>   BODY { ... }
> </style>
>
> <tal:block tal:replace="python: ..." />
>
> The first style block outputs non-dynamic style elements. Perfectly
> legal to have two <style> blocks, one after another.
>
> The conditional/dynamic style elements could be output by the tal:block.
> You'd have to output the start-style and-style tags, but in between,
> could do tal:block omit-tags="" as shown above. Would still be ugly but
> would work.
>
> In most cases, though, it's better to not inline your styles, but to put
> them in a .css doc and include this with a <link> tag -- easier to
> maintain, and the browser can use a cache for this link rather than
> getting it with every page. If you do this, you can have the included
> .css file use DTML, which IMHO, would be much easier for this kind of
> work.
>
> HTH.

I appreciate the response Joel, although this is pretty much what I had 
surmised for myself.  It doesn't seem that unsightly to me, though, to use 
TAL to sort out my code.  

Let me explain my situation in a little more detail.

I have several frames, one of which (the bottom frame) contains a text box 
and a sumbit button.  The bottom frame always contains only submit buttons 
and sometimes textboxes.  The middle frame is most of the page, and contains 
a form.  The top frame is irrelevant here.

Everything is rendered using ZPT, and the bottom frame shares its rendering 
code with many other pages.

What I want to do is enter data in the bottom frame and submit that data to 
the form in the middle frame.

It's simple enough to submit a form with one short ECMAScript function but 
what I want to do is add data to the form depending on what text boxes are in 
the bottom frame.  That means the client side script needs an awareness of 
what data it needs to add.  The obvious solution to this is to generate the 
contents of the <script> tag in the bottom frame dynamically and make a few 
changes depending on what else is being rendered in the bottom frame.

Like I said (well, implied), I can live without this and use Python scripts 
to do it but it seems like a rather contrived way of doing something very 
simple.

The external file doesn't really help since, obviously, I don't want the 
browser caching the script because it potentially changes every page.


By the way, in a <tal:block> (or <tal:whatever> ) you don't need to 
explicitly put every attribute in the tal namespace, you can just do 
<tal:block replace="blah"> :-)