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

I'm trying to use HTML::Template in my script. I have wdi.tmpl in the same folder as my script, and I use these lines:

my $template = HTML::Template->new(filename => 'wdi.tmpl'); # Later... $template->param(DIRLINKS => "1"); $template->param(CONTENT => "2"); # At the end... $template->output();

However, no matter what I do I only get a blank page. I viewed the source and it looks like it's just a standard 'blank page' line. What am I doing wrong?

Edited by davido: Added code tags and fixed HTML.

Replies are listed 'Best First'.
Re: HTML::Template Isn't Working
by dws (Chancellor) on Aug 06, 2004 at 00:01 UTC
    I viewed the source and it looks like it's just a standard 'blank page' line. What am I doing wrong?

    Try

    print $template->output();

    Also, you'll need to ensure that you print a valid HTTP response header first.

    print "Content-type: text/html\n\n";

    will do.

Re: HTML::Template Isn't Working
by gryphon (Abbot) on Aug 06, 2004 at 01:22 UTC

    Greetings rjahrman,

    To follow-up on what dws wrote, yes, you want to use print for the output if you're using HTML::Template alone. If you're using H::T along with something like CGI::Application, you may (depending on WWYWTDI) want to return the output instead of print.

    Good luck.

    gryphon
    code('Perl') || die;