in reply to HTML::Template and authenticated sessions

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?"
  • Comment on Re: HTML::Template and authenticated sessions

Replies are listed 'Best First'.
Re^2: HTML::Template and authenticated sessions
by samtregar (Abbot) on May 10, 2005 at 20:16 UTC
    You have to pass discrete values to H::T and that gets really annoying to code up, both in Perl and in templates.

    Say what? There's lots of ways to make this easy. Your "config object" could support a param() method, for example, allowing this to work:

    $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

      (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.

      1. You are going to litter your templates with a huge number of <TMPL_IF CONFIG_FOO_1> type statements.
      2. 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?"
        You are going to litter your templates with a huge number of <TMPL_IF CONFIG_FOO_1> type statements.

        And? You need conditional behavior, you use a tmpl_if. I don't see a problem here.

        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.

        So use one of the other two solutions I presented, or don't associate your query object. I don't do that much anymore personally - it's too hard to police.

        The alternative that TT provides is a method-like invocation on your objects.

        So you like your syntactic sugar. I get it. What does this have to do with session handling?

        Plus, you have run-time includes, which H::T (AFAIK) does not support.

        If you can't figure out how to do this with HTML::Template's filter option then you need to try a little harder!

        -sam

        PS: When do you want me to break out the benchmarks? You know they're coming!

Re^2: HTML::Template and authenticated sessions
by jeffa (Bishop) on May 10, 2005 at 18:07 UTC

    Actually ... one could theoretically get away with using HTML::Template::Expr ... but i do love the look and feel of Template Toolkit. :)

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re^2: HTML::Template and authenticated sessions
by ghettofinger (Monk) on May 10, 2005 at 18:19 UTC

    Is TT what perlmonks uses? I can start using it, but I really enjoyed HTML::Template. Are there any good links talking about this subject with Template::Toolkit?

    --gf