#!/usr/bin/perl
use strict;
use warnings;
use CGI::FastTemplate;
my $tpl = new CGI::FastTemplate("/some/directory");
$tpl->no_strict();
$tpl->define(main => "test.htm");
$tpl->assign(TEST_CONTENT=> "Test");
$tpl->parse(CONTENT => "main");
$tpl->print('CONTENT');
< html>
< head>
< title>TEST< /title>
< /head>
< body>
$TEST_CONTENT
< /body>
< /html>
Why can't I see the desired output in a browser? When I navigate to the test.cgi file all I see is the actual code and not the template. What am I doing wrong?
You are seeing code instead of the output of the program because you haven't configured you webserver to execute the program, so it is defaulting to serving the file as text/plain.
How you configure it depends on the server software you use. For example, see the Apache 2.2 CGI docs.
Second, the shebang line is missing. The program should start with:
#!/usr/bin/perl
Where /usr/bin/perl is the path to the Perl executable you wish to use.
Additionally, and not contributing to the problem:
use strict; and use warnings;. There should be boilerplate in any Perl program you are using as they catch many problems.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With