Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

HTML::Template Problem

by shockme (Chaplain)
on Mar 27, 2002 at 03:55 UTC ( #154580=perlquestion: print w/replies, xml ) Need Help??
shockme has asked for the wisdom of the Perl Monks concerning the following question:

I'm in the process of using my second template (ever), and I've run into a problem. It might be perl-related, or it could turn out to be just an HTML problem. I've stared at the script and template until I'm cross-eyed, and I just can't find the problem. You can see the script execute here.

The problem occurs in the textarea box below the Title. There's nothing there. What I'm expecting to see is this:

Title: Test Node #1 It might someday have something about perl or slashdot or [http://www.] or [|ttuhsc] or anything I want.
If you view source, it's there. But it's not being displayed in the form.

The script looks like this:

#!/usr/bin/perl -w use strict; use CGI qw/:all/; use exitwound::AccessData qw(&accessData); use HTML::Template; $|++; # disable buffering my $q = new CGI; my $NodeID = $q->param( "NodeID" ); my $ActionName = $q->param( "ActionName" ); my $NodeTitle = $q->param( "NodeTitle" ); my $NodeDate = $q->param( "NodeDate" ); my $NodeSection= $q->param( "NodeSection" ); my $NodeAuthor = $q->param( "NodeAuthor" ); my $NodeContent= $q->param( "NodeContent" ); if (($NodeID) and ($ActionName eq "Modify")) { $ActionName = "Update"; } elsif ($NodeID) { $ActionName = "Modify"; } else { $ActionName = "Insert"; $NodeID = "Unspecified"; } my @DisplayContent; ($NodeID, $NodeTitle, $NodeDate, $NodeSection, $NodeAuthor, $NodeConte +nt, @DisplayContent) = accessData($NodeID, $NodeTitle, $NodeDate, $NodeSection, $NodeAu +thor, $ActionName, $NodeContent); my $template = HTML::Template->new(filename => 'templates/mod-node.tmp +l'); $template->param(NodeSection => $NodeSection, NodeTitle => $NodeTitle, NodeAuthor => $NodeAuthor, NodeDate => $NodeDate, NodeContent => $NodeContent, ActionName => $ActionName, DisplayContent => @DisplayContent, ); print $template->output;
The template is in my scratch pad. (For some reason, it would not display properly here.)

Any advice or insight as to why nothing is being displayed in the textarea box would be greatly appreciated.


If things get any worse, I'll have to ask you to stop helping me.

Replies are listed 'Best First'.
Re: HTML::Template Problem
by grep (Monsignor) on Mar 27, 2002 at 04:05 UTC

    You're using the 'textarea' tag incorrectly.

    You want (I'm guessing on the HTML::Template stuff):
    <TEXTAREA NAME="NodeContent" ROWS="100" COLS="20"> <TMPL_VAR NAME=NodeContent> </TEXTAREA>
    Instead of:
    <TEXTAREA COLS=100 ROWS=20 NAME=NodeContent value="<TMPL_VAR NAME=Node +Content>">
    Here is a link on the syntax for textarea

    grep> cd /pub
    grep> more beer
      Oh man. Thanks! I've only stared at that for about 3 hours tonight. It could not have been more glaring.

      Thanks again!

      If things get any worse, I'll have to ask you to stop helping me.

      Unless the data in NodeContent is already escaped, you should add the ESCAPE=HTML attribute to your TMPL_VAR tag, so that HTML special chracters such as < are escaped. See the HTML::Template documentation and the relevant HTML specification for details. I'd write something like:
      <TEXTAREA NAME="NodeContent" ROWS="100" COLS="20"> <!-- TMPL_VAR NAME=NodeContent ESCAPE=HTML --> </TEXTAREA>
Re: HTML::Template Problem
by gav^ (Curate) on Mar 27, 2002 at 04:39 UTC
    It seems that your question has been answered but I thought I'd leave you with my biggest HTML::Template suggestion: put your HTML in lowercase and uppercase your HTML::Template tags, for example:
    <p><b>This is some text:</b> <TMPL_VAR NAME=MY_VAR></p>
    This makes it stand out a lot more, helping to notice tags amongst all the HTML.


      I'd go one step further and write HTML::Template tags as comments:

      Hello, <!-- TMPL_VAR NAME="name" -->

      HTML::Template knows how to process these comment-style tags. The advantage of this is that you can run your templates through an HTML validator without any processing because the validator treats the HTML:::Template tags as HTML comments.

Re: HTML::Template Problem
by jlongino (Parson) on Mar 27, 2002 at 06:03 UTC
    A suggestion. You really ought to use an HTML validation product. Particularly during CGI debugging stages. There are many available (and free) on the web CSE HTML Validator Lite being one of them. You still have basic html errors on your page.

    There is plain text before your <HTML> tag, you have a <TD> right after a </TR> tag and a missing or extra </TR> tag towards the end. If you had, in fact used TEXTAREA incorrectly, that would've shown up as well.


      Another HTML validator that I can personally attest to is HTML Tidy by Dave Raggett.

      And it is open source.


Re: HTML::Template Problem
by Anonymous Monk on Mar 27, 2002 at 04:02 UTC
    well what if the textarea content contains a doubleqoute? you run into trouble. anyway, it should be
    <TEXTAREA> content </TEXTAREA>
Re: HTML::Template Problem
by dws (Chancellor) on Mar 27, 2002 at 04:03 UTC
    In addition to the tag problem, it doesn't appear that you're emitting a Content-Type: header.
      Okay, I was wondering about this. According to the HTML::Template Tutorial, I don't have to (unless I've really mis-read the whole thing).

      When using HTML::Template, do I still have to issue the Content-Type header?

      If things get any worse, I'll have to ask you to stop helping me.

        When using HTML::Template, do I still have to issue the Content-Type header?

        I consider the HTML::Template POD to be authoritative (well, the code is, too). As of version 1.8, you need to supply the header.

        I don't think so. HTML::Template uses CGI, so no.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://154580]
Approved by root
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2018-05-26 08:31 GMT
Find Nodes?
    Voting Booth?