Skip to main content.
home | support | download

Back to List Archive

Re: Swish-E and CSS

From: Bill Moseley <moseley(at)not-real.hank.org>
Date: Fri Apr 16 2004 - 00:57:08 GMT
On Thu, Apr 15, 2004 at 01:58:23PM -0700, Phil Matt wrote:
> On 15 Apr 2004 at 12:44, Bill Moseley wrote:
> 
> 
> > If using the TemplateDefault module to generate output then how about
> > adding something like:
> > 
> >    print `cat /path/to/include/file`;
> > 
> I'm not following this.

It's a perl statement.

With TemplateDefault the (HTML) output is generated in Perl code.  For
example, there's a subroutine called "page_header()" that prints our the
first part of the page -- part that's the same regardless of the search
results.

It does this (which I think you have modified):

    return <<EOF;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
       <title>
          $html_title
       </title>
    </head>
    <body>
        <h2>
        $logo$title $message
        </h2>
EOF


where $html_title, $logo, $title, and $message are generated in perl code.

So just modify it to meet your needs:

    # Fetch standard site menu
    my $menu = `cat /path/to/menu/file.txt`;

    return <<EOF;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
       <title>
          $html_title
       </title>
    </head>
    <body>
        <h2>
        $logo$title $message
        </h2>

        <!-- left side bar with menu -->
        <div class="site-menu">
            $menu
        </div>
EOF


Or maybe place in a table if you don't want to use css for placement.



Now, I wouldn't normally use "cat" like above, but it was a one-line
example.  Maybe something like this:

   # Open file and abort on error
   open( FH, "<$menu_path" )
        or die "Failed to open menu file '$menu_path': $!";

   # Read in menu HTML

   local $/;  # undefine input record separator
   my $menu = <FH>;  # slurp in entire file;
   die "No menu loaded from file $menu_path"
        unless $menu;


Which is kind of a pain.  Which is why it's nice to use a templating
language all that stuff is done for you and then you just say:

    <div class="site_menu">
        [% INCLUDE site_menu %]
    </div>

For more examples look at the search.cgi example script that uses
Template-Toolkit -- the template in the program is embedded right in the
script after the __DATA__ mark in the file, but normally the template
would be a separate file -- and every one of those BLOCK sections might
also be in a separate file (or row of a table in a database).

Not that I'm pushing Template-Toolkit.


-- 
Bill Moseley
moseley@hank.org
Received on Thu Apr 15 17:57:14 2004