Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Please give some direction in opting for an array value in a template?

Quote Reply
Please give some direction in opting for an array value in a template?
Hi all,
1) I used <%GT::Template::dump%> in the template to view the variable:

in bless(
{
'_debug' => '0',
'cookies' => {somevalue/or empty}
});

2) I would like to opt for the value of the "cookies" in the templates as:

<%if in.cookies%>
display this
<%else%>
this play this
<%endif%>

The above is not working. Could you give some direction in implement my intention?
thank you, pyc
Quote Reply
Re: [pyc] Please give some direction in opting for an array value in a template? In reply to
The $in variable is special in GT::Template - it's a GT::CGI object. GT::Template handles this object differently where when you use <%in.foo%> it will return the equivalent of $IN->param('foo'). This means you can't access the cookies from the $in template variable. If you want to access cookies, you'll have to do it in code (ie. using globals). Something like:
Code:
sub {
my $cookie = shift;
return unless $cookie;

return $IN->cookie($cookie);
}
Then in the templates (assuming you named the above global get_cookie), do:
Code:
<%if get_cookie('my_cookie')%>
give my_cookie back!
<%else%>
take my_cookie.
<%endif%>

Adrian