in reply to Page Templates

Another way to do it would be to have the user supply a fully written html tempate but use special tags in it to place different items. You define those tags in your script
$item1 = "blah blah blah blah"; $item2 = "<img src=\"http://sitename.com/images/foo.gif\">"; $pagecontents = "Hello world\n"; $pagecontents .= "
\nHow are you\n
\n";
Then when you're ready to display the page results, open the template, read in the contents and replace the tags with the information you want
$templatefile = "template.html"; open(LOCAL, "<$templatefile") || &error('Cannot Open Template File'); if ($^O eq "dos") { binmode LOCAL; } else { flock(LOCAL, 2); } @template = <LOCAL>; close LOCAL or &error('Cannot Close New File'); foreach $line(@template) { $line =~ s/<insert item1>/$item1/g; $line =~ s/<insert item2>/$item2/g; $line =~ s/<page body>/$pagecontents/g; print "$line"; }

Replies are listed 'Best First'.
2Re: Page Templates
by jeffa (Bishop) on Feb 11, 2004 at 16:55 UTC
    Please consider using HTML::Template instead of rolling your own solution like you have done. It's tested, it works, it's supported ... it's free. :)

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)