prarie dawn has asked for the wisdom of the Perl Monks concerning the following question:

I'm thinking about layouts for HTML. I know alot has been written about XML, CSS, etc for seperating content from the look-and-feel.

I'm interested in making the look-and-feel as customizable as possible. More than just changing styles of text - I'd like to be able to change the order of the components, and the manner in which the components are layed out. By components I guess I mostly mean text boxes like Chatterbox. Each component can have it's own layout xml file, describing the order and manner inwhich it's components are displayed. For Example, the Chatterbox layout file might specify that the Talk input appear at the top.

I guess I'd just like peoples thoughts. I know there are many existing projects that must touch on this.

A big concern I have is how to implement components in perl. If perl was reading a layout file on-the-fly, and it discovered it required to render component X, then X could be a class of sorts, but:
  1. How to load the class X in a timely and memory efficient way? (I like the idea of Java Servlets - is there a similar model for perl?)
  2. How to make X aware of the environment restrictions that it is rendering to? (eg: the background colour is white and you have 300 width to work with ... please don't do not use yellow as your text colour and do not create any 600-width tables! ... I'm thinking that there might have to be a certain level of trust on this!)


thanks
Prarie Dawn

Replies are listed 'Best First'.
Re: Laying out a web page
by Mission (Hermit) on Jun 10, 2001 at 14:43 UTC
    First off, welcome to Perl Monks prairie dawn. Now to try to answer your question. You will find out that TMTOWTDI (There's More Than One Way To Do It) so I'll throw a few ideas at you, and I'm sure that the other monks will as well. Take the best from all of us and keep us informed of the progress. I think this answer comes in two steps, the first one is Off Topic (design), but the second is Perl. I'll cover both of them briefly.

    The first suggestion I have is not in perl, but in design. The elements that you are comparing to at Perl Monks, are all laid out in a similar manner so it's easy to customize what goes where. For example, if I want to change the position of the Chatter Box, with my Personal Nodelet, I can because they are both on the right hand side with the same design elements (width, color scheme, etc.) So you will need to design all of your elements so they are interchangeable. This is step one. Do numerous mock-ups in HTML and make sure that all parts are interchangeable.

    The Perl answer (or at least one of them) is HTML::Template module. You can seperate your perl from your 'design' and in the Template, your design has some basic if logic, loop logic, and can pull in variables from your Perl. I suggest that you start your research (at least the Perl side) on HTML::Template and keep asking questions posting code where you are having troubles. Good luck.

    - Mission
    "Heck I don't know how to do it either, but do you think that's going to stop me?!!"
Re: Laying out a web page
by arturo (Vicar) on Jun 10, 2001 at 22:19 UTC

    An approach you might look into is using generating the page content as XML and then transforming that XML using some kind of stylesheeting system; AxKit is an XML publishing application that runs under mod_perl; it can use different kinds of XML stylesheets, including the most popular, XSLT. The basic idea is that the XSLT instructions take XML content and transform it into HTML (or XML, or plain text, or PDF, or ...)

    The beauty of XML stylesheets is that you have complete control over the resulting HTML; not only can you control colors, background images, etc. as you can with CSS, but you can control the order of appearance of elements (or even whether a given element will appear at all). You can customize the HTML you produce for different browsers (i.e. you don't have to write HTML that degrades gracefully; you can use all the bells and whistles supported by IE 5.5 for users with IE 5.5, and you can output straightforward HTML 3.2 for users with Netscape 3.0). And of course you can define different stylesheets for different themes.

    It's a really flexible system. The drawback is that it's pretty complex. The big plus, other than the flexibility, is that you can achieve a *very high* degree of separation between content and presentation.

    perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'
Re: Laying out a web page
by gildir (Pilgrim) on Jun 11, 2001 at 20:03 UTC
    We have done this in Jewels Application framework. All output is porduced as a XML fragments, they are clued together and then converted to HTML. Your 'component' is called 'Jewel' here (hence the name). It runs in Apache/mod_perl environment. Have a look at it (jewels.bgs.sk).