in reply to Sticky HTML Templates

Unless I misread the docs and added unnecessary default statements in my first foray with TT2, if you use a [% USE CGI %] and the appropriate CGI calls with the TT2 document, it's as sticky as perl's CGI.pm calls.

Update Expanding as requested by boo below:

If I write this template and call it from my perl code as given:

[% USE CGI %] [% CGI.header %] [% CGI.h1( "Hello World!" ) %] [% CGI.start_form %] [% CGI.textbox( { name=>"text" } ) %] [% CGI.submit %] [% CGI.end_form %]
Then in effect, ignoring template substitutions that may happen, it is the same as this perl code:
#!/usr/bin/perl use CGI; my $q = new CGI; print $q->header(), $q->h1( "Hello World!" ), $q->start_form(), $q->textbox( -name=>"text" ), $q->submit, $q->end_form;
Specifically, the CGI object as created by TT2 acts just like the CGI object in perl, and thus knows how to capture the passed parameters and knows how to fill in default values. There's minimal docs on this here, but from my experience working with it, that appears to be the case. Please note the code above is OTTOMH, only to demonstrat the point.

-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
"I can see my house from here!"
It's not what you know, but knowing how to find it if you don't know that's important

Replies are listed 'Best First'.
Re: Re: Sticky HTML Templates
by boo_radley (Parson) on Oct 25, 2001 at 22:23 UTC
    Please expand on this.

      I'm playing with this now. Here's what I have:

      <textarea cols="45" rows="3" name="event"></textarea>

      This becomes:

      [% USE CGI %] <textarea cols="45" rows="3" name="event">[% CGI.param('event') %] +</textarea>

      It performs as advertised, but doesn't escape any of the HTML characters, so typing </textarea> in the textarea will break it. It appears that the HTML plugin can fix this, but I don't have that installed (yet).

      I'm going to have to give this some thought. It's a quick and easy way to make some things sticky, but I don't see how it would work with a select group, for example. I'll second your request to have masem expand on this :)

      Update: Hmm... I see what masem is doing, but that kind of defeats part of what I need: a simple, easily maintainable template that our designers can go into a work on. Interesting, though.

      Cheers,
      Ovid

      Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

        It performs as advertised, but doesn't escape any of the HTML characters, so typing </textarea> in the textarea will break it. It appears that the HTML plugin can fix this, but I don't have that installed (yet).

        Looks like TT2 do need "escaping expressions" feature that exists in HTML::Mason for so long: you can add one or several escape flags at the end of expression to be expanded. <% $text_that_should_be_escaped |h%> will do exactly what you want - escape all special HTML-entities. Morover, you can customize default escape flags to avoid writing them everywhere or to change behaviour of existing components.

        -- brother ab