Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: HTML::Template question - tmpl_if

by djantzen (Priest)
on Dec 14, 2003 at 01:44 UTC ( #314594=note: print w/replies, xml ) Need Help??

in reply to HTML::Template question - tmpl_if

Hi kiat,

The code you posted runs just fine for me, and under strict and warnings to boot. The only way I could elicit the error you describe is by intentionally inserting either undef, a string literal, or an actual scalar in for the value of options. If the key is simply absent -- as in your template output 2 -- then the output looks as it should. There's nothing to iterate over and so no loop contents displayed. Are you positive that's what is actually generating the error?

"The dead do not recognize context" -- Kai, Lexx

Replies are listed 'Best First'.
Re: Re: HTML::Template question - tmpl_if
by kiat (Vicar) on Dec 14, 2003 at 01:55 UTC
    Hi djantzen,

    Thanks for helping!

    In my attempt to simplify, I left a subroutine out. I've included it in the latest update. The subroutine takes a hash and prepare it for output to HTML::Template.

    I would appreciate very much your taking a look at it again.

    Thanks in advance :)

      Well this is somewhat poor style, but you could say something like:

      options => defined($hashref->{'options'}) || []

      How about a nice map though that only pulls out the defined elements in your hash?

      map { defined $hash->{$_} ? ($_ => $hash->{$_}) : () } keys %$hash;

      The output then can be fed directly into param. This is limited too in that it assumes your hashkeys are identical to your fields (TMPL_VARS), but if you can live with that assumption it might work for you.


      "The dead do not recognize context" -- Kai, Lexx
        Thanks, the first solution works for me.

        I didn't get the second solution to work. How do you get it work work given the code I gave about (the %hash and the generate subroutine).

        Finally, how would you have set up a template like this?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://314594]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2021-01-24 10:02 GMT
Find Nodes?
    Voting Booth?