Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Re: HTML::Template question - tmpl_if

by kiat (Vicar)
on Dec 15, 2003 at 00:32 UTC ( [id://314725]=note: print w/replies, xml ) Need Help??


in reply to Re: HTML::Template question - tmpl_if
in thread HTML::Template question - tmpl_if

Thanks, punkish!

I did a dump of @options.

# This dumped output of options is #$VAR1 = { 'school' => 'Admiralty Primary', 'school_id' => '1' }; #$VAR2 = { 'school' => 'Ahmad Ibrahim Primary', 'school_id' => '2' }; #$VAR3 = { 'school' => 'Anderson Primary', 'school_id' => '3' }; # the relevant template is # note that the school_id in <select name="school_id"> is # hard-coded whereas the one in <tmpl_var name=school_id>"> # is a number supplied via @options <select name="school_id"><option selected value="1"><option selected v +alue="0">Select<tmpl_loop name=options> <option value="<tmpl_var name=school_id>"><tmpl_var escape=html name=s +chool></option></tmpl_loop> </select></td></tr>
The above works with the template but I'm not sure if I'm missing something. Note that %hash is passed to &generate (thanks to djantzen for the map) which generates a list which is then supplied to the param of H::T.

Replies are listed 'Best First'.
Re: Re: Re: HTML::Template question - tmpl_if
by punkish (Priest) on Dec 15, 2003 at 01:38 UTC
    I am not sure what your question is this time around. You write...
    The above works with the template but I'm not sure if I'm missing something.
    If it works, then you are not missing anything. Your template code is, though, a bit confusing. You have typed (perhaps, a typo) --
    <select name="school_id"><option selected value="1"><option selected v +alue="0">Select<tmpl_loop name=options> <option value="<tmpl_var name=school_id>"><tmpl_var escape=html name=s +chool></option></tmpl_loop> </select>
    Perhaps you meant --
    <select name="school_id" size="1"> <option selected value="0">Select school</option> <tmpl_loop options> <option value="<tmpl_var school_id>"><tmpl_var escape=html school> +</option> </tmpl_loop> </select>
    Wrt your original question, no matter how you do it, just remember that in H::T each variable is a scalar, while each loop is an array of hash(es). You'll be ok. If you want to not set anything, you can do one of two things -- turn die_on_bad_params off by setting it to 0, or better yet, make sure you set the value to an empty reference. Actually, you can do one more thing -- use tmpl_if to check for existence of a var before trying to display it. Good luck.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-26 07:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found