Re: HTML::Template and authenticated sessions
by samtregar (Abbot) on May 10, 2005 at 20:18 UTC
|
| [reply] |
Re: HTML::Template and authenticated sessions
by dragonchild (Archbishop) on May 10, 2005 at 17:43 UTC
|
You're going to want to use Template Toolkit instead of HTML::Template if you're tailoring display elements based on boolean values. You can pass a $config object to TT and then query it within your template. You have to pass discrete values to H::T and that gets really annoying to code up, both in Perl and in templates.
- In general, if you think something isn't in Perl, try it out, because it usually is. :-)
- "What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?"
| [reply] |
|
$tmpl = HTML::Template->new(filename => "...",
associate => $config);
Or your could just use a hash instead of an object and do:
$tmpl->param(%config);
Or you could keep your object and just write a method which returns the data in a hash, but is simpler than a full param():
$tmpl->param($config->hash());
In short, this is hardly a reason to drop HTML::Template (and has hardly anything to do with session handling).
-sam
| [reply] [d/l] [select] |
|
(First off, let me say that I'm a long time H::T user, occasional TT dabbler. I love what you've done with the place, samtregar.)
You can associate, but you have two problems, neither of which are solvable with the H::T syntax.
- You are going to litter your templates with a huge number of <TMPL_IF CONFIG_FOO_1> type statements.
- If you associate more than two objects, collisions are a very real possibility, especially if you associate your $cgi and $config objects at the same time.
The alternative that TT provides is a method-like invocation on your objects. Plus, you have run-time includes, which H::T (AFAIK) does not support. This is much easier to work with.
- In general, if you think something isn't in Perl, try it out, because it usually is. :-)
- "What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?"
| [reply] [d/l] |
|
|
|
|
|
| [reply] |
|
| [reply] |
Re: HTML::Template and authenticated sessions
by arc_of_descent (Hermit) on May 10, 2005 at 17:52 UTC
|
You should check out CGI::Session. I personally would not suggest the use of a cookie as a session tracking thingie. I mean, there is always the possibility of the client side (can be a script, browser) not accepting cookies. It is relatively easy to track sessions using server side logic. Based on your session ID (which uniquely identifies each user), you can then output different HTML templates. You would of course have to decide on a convenient naming scheme for your template files, or you could generate these templates in your Perl script itself (based on session ID)
| [reply] |
|
| [reply] |
|
| [reply] |
|
Yeah, I'd like to second the above question. How the hell do you associate session id's with a client's request with out cookies? Sure you could embed session ids in the url, but that is hideously ugly and very prone to insecurities, such as sharing urls.
| [reply] |