[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Using MacPerl to Generate HTML



I believe there are a number of HTML template modules on CPAN that might
help you out.  I haven't used any of them, though.

Instead, I generally do something along the lines of the sample code
below.  In short, I define a bunch of HTML comments--each on its own
line--in a template file, and then substitute the text I want for the
appropriate HTML comment.  The code snippet below shows you one way to do
that.

Good luck!
Matt

----------- TEMPLATE FILE ------------------------
<html>
 <head>
  <title>The Title</title>
 </head>

 <body bgcolor="#e6e6e6">
     <img src="Images/contents.gif" alt="Contents">
     <br>
      <!-- TOC:SECTION1 -->
      <!-- TOC:SECTION2 -->
      <!-- TOC:SECTION3 -->
 </body>

</html>


--------------- CODE TO FILL TEMPLATE FILE ------------------------------
    use Mac::Files;

    my $section1 =  "TOC:SECTION1";
    my $section2 =  "TOC:SECTION2";
    my $section3 =  "TOC:SECTION3";

    # You would fill these variables from the file
    # containing the data you want displayed
    my $textForSection1;
    my $textForSection2;
    my $textForSection3;


     open(INFILE, "<$templatesDir:$tocFSName") ||
         die "Can't open $templatesDir:$tocFSName.\n";
     my @tocLines = <INFILE>;
     close INFILE;

     foreach my $line (@tocLines) {
         if ($line =~ /$section1/) {
            $line = "$textForSection1<br>\n";
         }
         if ($line =~ /$section2/) {
            $line = "$textForSection2<br>\n";
         }
         if ($line =~ /$section3/) {
            $line = "$textForSection3<br>\n";
         }
     }
     open(OUTFILE, ">$outputDir:$tocFSName") ||
         die "Can't write $outputDir:$tocFSName.\n";
     print OUTFILE @tocLines;
     close OUTFILE;
     MacPerl::SetFileInfo("MSIE", 'TEXT', "$outputDir:$tocFSName");
----------------

Robert Gilman wrote:

> I'm working on a Web site for a local theatre group, and want to set it
> up for maximum ease of maintenance. My thought was to set up the
> calendar, and certain standard sections, e.g., news, details of current
> productions, so that the group could simply enter values in a file
> containing a set of variables, and a script would generate the HTML for
> the Web page using those values.
>
> I'm a newcomer both to Perl & MacPerl. Any help in pointing me to
> resources to accomplish this sort of task would be much appreciated.
>
> Bob Gilman
>
> # ===== Want to unsubscribe from this list?
> # ===== Send mail with body "unsubscribe" to macperl-request@macperl.org


# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org