[Zope] Re: External CSS via ZPTs

Casey Duncan casey@zope.com
Sat, 29 Jun 2002 17:40:37 -0400


Unless your style sheet is dynamic, I would just use a file object. As of
Zope 2.5, you can edit textual ones through the web or you can use FTP, DAV
or external editor. Just set the content type property to "text/css". Then
link to it the usual way in your standard template.

File objects will automatically set the proper headers that all
browsers/proxies to cache them. If  you use DTML, you will need to set the
headers yourself or use an HTTP cache manager, which I would highly
recommend unless your CSS is browser specific, in which case that is not
possible.

If there are browser specific parts I might suggest the following:

Put the non-browser specific parts in a file object. Then create a DTML
method (or a Python script if you don't feel like using DTML) to generate
the browser specific parts. Set a RAM cache manager up for this object
keyed to the data that would make the CSS different, such as
AUTHENTICATED_USER and/or HTTP_USER_AGENT. This will keep Zope from having
to render the dynamic CSS on every request.

Then setup your standard template to link to the CSS file object (which is
static). Following that add a <style> tag that inlines the dynamic part
right into each page. That way, the browser only has to make one request in
most cases (since the static css will be cached).

For large static pages, you could opt to link to the dynamic CSS rather than
inline it so that the static content is cacheable. For dynamic (or small
pages), the extra request will be more significant, so inline it instead.

By placing the bulk of your CSS in a static file and the rest inline, your
pages will render without so much "jumping" as well. If the browser has to
download all the CSS everytime (because its non-cacheable), then many will
render the page without CSS first and again once the CSS comes down. This
makes for a rather jerky user experience.

hth,

-Casey

----- Original Message -----
From: "Shane McChesney" <shane@nooro.com>
Newsgroups: gmane.comp.web.zope.general
Sent: Saturday, June 29, 2002 10:48 AM
Subject: External CSS via ZPTs


I'd like to use a CSS stylesheet editable within the Zope Management
Interface, and refer to it from a LINK tag in the HEAD of each page.

I'm just learning Zope, and trying to stick to ZPTs over DTML
wherever possible.

I searched Zope.org, and found mindlace's post of a "CSS & Zope
howto" in 1999.

It talks about using the LINK tag to incorporate external CSS that is
still an editable Zope object, exactly what I want, but it's a DTML
object, and I'm not sure how to replicate this line in a ZPT:

From: http://www.zope.org/Members/mindlace/css_zope
----------------------------------------------
IMPORTANT: You must have the following line as the first line of your
method:

<dtml-call "RESPONSE.setHeader('Content-Type', 'text/css')">
----------------------------------------------

How can I have a ZPT act as my external stylesheet and set that
response header? That is, how do I emulate the dtml-call above in a
ZPT?

Thanks,

Shane McChesney
http://www.skippingdot.net



_______________________________________________
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 )