[Zope] Skins - a few questions (LONG)

maxm maxm@normik.dk
Wed, 22 Dec 1999 11:25:50 +0100


Hi

I, like a lot of other people have fallen in love with Zope, and I can see
the benefits of it all. Therefore I will start working in this enviroment
from now on.

One of the things I would really like is the ability to make skins. A way to
make different layouts that can be changed at a whim. Very useable for
instance when somebody wants to browse a site with the Lynx browser, and
somebody else wants to use the Acme 17.6 browser, or you simply want to use
the same logic to drive sites with different layouts. A products like
squishdot would be a prime candidate for this.

The skin could be choosen on a per session base or dependening on what
browser is used or saved in a user preference setting or all of the above.

I have been working with IIS/ASP and Apache/PHP for a while and have made
various skin systems in these enviroments.

the general idea is that i make some templates into which I insert the
content and then call these templates as functions:

---------------------------------------------------------------
PHP examples:

function Box($Title, $Content){
    return "
    <table width=100% Border=0 cellpadding=3 spacing=0>
        <tr bgcolor=darkgreen>
            <td>
                <font size=-1 color=white><b>$Title</b></font>
            </td>
        </tr>
        <tr>
            <td>
                <font size=-1>$Content</font>
            </td>
        </tr>
    </table>
    "
}


function Page($Title, $Content){
    return "
    <html>
    <head>
        <title>$Title</title>
    </head>
    <body>
        <h2>$Title</h2>
        $Content
    </body>
    </html>
    "
}


All I have to do then when rendering a page in PHP is to write this:
<?
    echo Page('Testexample','You are welcome')
?>

I can change alle my layout for the whole site in one place and the pages a
wonderfully short with only the page logic being different on each page. I
hate when html and logic is mixed on the same page.

I have also made sites where the pages are saved as html files that I then
load and replace some keywords with the correct html via functions.

a simplified example can be seen here in python :

---
>!-- Template file shown here here -->
<html>
    <head>
        <title>Welcome to my site</title>
    </head>
    <body>
        %Content%
    </body>
</html>
---

def DK_Page(content):
    fileinput = open(TemplateFilePath + 'Template.htm' , 'r')
    FileContent = fileinput.read()
    fileinput.close()
    return re.sub(r'\%content\%', content, FileContent)

---------------------------------------------------------------

This is the same principle as the PHP example, but with the layout
completely seperated. The advantage here is that the page designer can have
a whole page to work in, and save it all as an HTML file and only has to
remember to put the %title% and %content% and other tags in the templates.

This is muche healthier for a designer I have found (I work at an
advertising agency with a lot of traditional Layouters).

Personally i don't like the traditional zope way of doing it with:

<!--#var html_header-->
content
<!--#var html_footer-->

As you have to split up a layout that really shouldn't be split. It's hard
for designers, a bit cumbersome, and it is errorprone allways having to
remember to cut a file in two and then uploading both.

Furthermore you cannot easily have different users use different skins this
way.

I would really like for the designers to be able to put up template html
files with a few keyword tags in them. ftp to the ZODB is fine, but a folder
in the filesystems would also suffice. A directory/file structure something
like this:

skins
    Skin1
        page.html
        box.html
        style.css
    Skin2
        page.html
        box.html
        style.css
    Skin3
        page.html
        box.html
        style.css

Well my real question comes here:

--------------------------------
1)

To get started I have made a dtml method called "box" in the root of my zope
site that looks like this:

<table spacing=3 border=0 padding=0 width=100%>
   <tr bgcolor=green>
      <td><font size=+1 color=white><b><!--dtml-var
theTitle--></b></font></td>
   <tr>
   </tr>
      <td><!--dtml-var theContent--></td>
   </tr>
</table>

How do I call it from a dtml document?

I have tried different things and I cannot seem to succed.

Perhaps I should user an external python method? this would be a lot more
like I am used to, but would probably result in bastard dtml.

--------------------------------
2)
Is there any other obvious way to do this in Zope? Would it be a waste of
time implementing a product like this as it would be easier to ...

--------------------------------
3)
Is there anybody who can see an obwious way to turn this functionality into
a product and perhaps give me a few hints or an outline. Any ideas are
welcome as I havn't yet grokked the zen of Zope.


------------------------------------------------------------------------
Max M Rasmussen,   New Media Director    http://www.normik.dk   Denmark
e-mail                                   mailto:maxm@normik.dk