Re: [Catalyst] Using a post argument in a template

2008-07-25 Thread Bill Moseley
On Fri, Jul 25, 2008 at 07:40:59AM -0500, James S. White wrote:
 I was trying to munge the paramaters in the controller,

You said argument in your original post:

sub foo : Local {
my ( $self, $c, $myarg ) = @_;

$c-stash-{myarg} = $self-munge( $myarg );
# or use chaining
}


 I just can't figure
 out how to access the variables of a controller method in the template.

Munged argument is [% myarg | html %]


 I'd
 be more than happy to pass the argument to a controller, and then have the
 view fetch it from the controller, and then the template read it from the 
 view,
 If I had any idea how to dereference the variables in order to set them in
 new components. I was just trying to keep it walk before running and I keep
 tripping over my feet.

It's that wording that is tripping me up. ;)






 
 
 On Fri, 25 Jul 2008, Eden Cardim wrote:
 
  On Fri, Jul 25, 2008 at 1:12 AM, James S. White [EMAIL PROTECTED] wrote:
   I'm passing an argument to the method via a post, and then catch it with
   my ( $self, $c, $myarg ) = @_; shouldn't there be a way to mine it without
   using [% c.req.arguments.0 %] in the template?
  
   like [% c.controller('Page').methodname.myarg %] or something...
 
  You want [% c.req.body_params.myarg %] if it's a post, [%
  c.req.params.myarg %] if you don't care. I would munge the parameters
  in the controller and try to formalize an API to interact with the
  view though. Also, avoid making your view-side code be
  controller-dependent, you'll surely regret it later.
 
  --
  edenc.vox.com
 
 
 
 ___
 List: Catalyst@lists.scsys.co.uk
 Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
 Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
 Dev site: http://dev.catalyst.perl.org/
 

-- 
Bill Moseley
[EMAIL PROTECTED]
Sent from my iMutt


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Using a post argument in a template

2008-07-25 Thread Tomas Doran


On 25 Jul 2008, at 13:40, James S. White wrote:

I was trying to munge the paramaters in the controller, I just  
can't figure
out how to access the variables of a controller method in the  
template. I'd
be more than happy to pass the argument to a controller, and then  
have the
view fetch it from the controller, and then the template read it  
from the view,
If I had any idea how to dereference the variables in order to set  
them in
new components. I was just trying to keep it walk before running  
and I keep

tripping over my feet.



You want to put the data into the 'stash'.

So in your controller you have:
my ( $self, $c, $arg ) = @_;
$arg =~ s/stuff/munge/;
$c-stash-{somearg} = $arg;

And in your view, you say: [% c.stash.somearg %]

You don't really want the view to be able to see the controller's  
internal state / mechanics, and so you have to explicitly stash any  
data which you want to be able to see from the view.


HTH
t0m


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Using a post argument in a template

2008-07-25 Thread James S. White
I did. I want to use it as a variable even though it's passed in as an arg.
I didn't mean to be unclear, sorry. Once it's stashed, can I use it like
[% myarg %] in a template? or [% c.stash.myarg %]?

On Fri, 25 Jul 2008, Bill Moseley wrote:

 On Fri, Jul 25, 2008 at 07:40:59AM -0500, James S. White wrote:
  I was trying to munge the paramaters in the controller,

 You said argument in your original post:

 sub foo : Local {
 my ( $self, $c, $myarg ) = @_;

 $c-stash-{myarg} = $self-munge( $myarg );
 # or use chaining
 }


  I just can't figure
  out how to access the variables of a controller method in the template.

 Munged argument is [% myarg | html %]


  I'd
  be more than happy to pass the argument to a controller, and then have the
  view fetch it from the controller, and then the template read it from the 
  view,
  If I had any idea how to dereference the variables in order to set them in
  new components. I was just trying to keep it walk before running and I keep
  tripping over my feet.

 It's that wording that is tripping me up. ;)






 
 
  On Fri, 25 Jul 2008, Eden Cardim wrote:
 
   On Fri, Jul 25, 2008 at 1:12 AM, James S. White [EMAIL PROTECTED] wrote:
I'm passing an argument to the method via a post, and then catch it with
my ( $self, $c, $myarg ) = @_; shouldn't there be a way to mine it 
without
using [% c.req.arguments.0 %] in the template?
   
like [% c.controller('Page').methodname.myarg %] or something...
  
   You want [% c.req.body_params.myarg %] if it's a post, [%
   c.req.params.myarg %] if you don't care. I would munge the parameters
   in the controller and try to formalize an API to interact with the
   view though. Also, avoid making your view-side code be
   controller-dependent, you'll surely regret it later.
  
   --
   edenc.vox.com
  
 
 
  ___
  List: Catalyst@lists.scsys.co.uk
  Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
  Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
  Dev site: http://dev.catalyst.perl.org/
 

 --
 Bill Moseley
 [EMAIL PROTECTED]
 Sent from my iMutt



___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Using a post argument in a template

2008-07-25 Thread James S. White
Cool. I was unaware how the stash worked. I can see the benefit of encapsulating
each component. Thanks!

On Fri, 25 Jul 2008, Tomas Doran wrote:


 On 25 Jul 2008, at 13:40, James S. White wrote:

  I was trying to munge the paramaters in the controller, I just
  can't figure
  out how to access the variables of a controller method in the
  template. I'd
  be more than happy to pass the argument to a controller, and then
  have the
  view fetch it from the controller, and then the template read it
  from the view,
  If I had any idea how to dereference the variables in order to set
  them in
  new components. I was just trying to keep it walk before running
  and I keep
  tripping over my feet.
 

 You want to put the data into the 'stash'.

 So in your controller you have:
 my ( $self, $c, $arg ) = @_;
 $arg =~ s/stuff/munge/;
 $c-stash-{somearg} = $arg;

 And in your view, you say: [% c.stash.somearg %]

 You don't really want the view to be able to see the controller's
 internal state / mechanics, and so you have to explicitly stash any
 data which you want to be able to see from the view.

 HTH
 t0m



___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Using a post argument in a template

2008-07-25 Thread Tomas Doran


On 25 Jul 2008, at 14:50, James S. White wrote:

I did. I want to use it as a variable even though it's passed in as  
an arg.
I didn't mean to be unclear, sorry. Once it's stashed, can I use it  
like

[% myarg %] in a template? or [% c.stash.myarg %]?



Yes, either.

Cheers
t0m


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Using a post argument in a template

2008-07-25 Thread James S. White
I can stash and array and when I use [% c.stash.mylist %] in the template,
it prints 'ARRAY(0x94023b0)' but if I try:

[% FOREACH element IN c.stash.mylist %]
[% element %]
[% END %]

the output is null. I'm sure I'm missing something here, I just don't know what.


On Fri, 25 Jul 2008, Tomas Doran wrote:


 On 25 Jul 2008, at 14:50, James S. White wrote:

  I did. I want to use it as a variable even though it's passed in as
  an arg.
  I didn't mean to be unclear, sorry. Once it's stashed, can I use it
  like
  [% myarg %] in a template? or [% c.stash.myarg %]?
 

 Yes, either.

 Cheers
 t0m



___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Using a post argument in a template

2008-07-25 Thread James S. White
nevermind. this works. I am an idiot. It helps if the array isn't empty...

On Fri, 25 Jul 2008, James S. White wrote:

 I can stash and array and when I use [% c.stash.mylist %] in the template,
 it prints 'ARRAY(0x94023b0)' but if I try:

 [% FOREACH element IN c.stash.mylist %]
 [% element %]
 [% END %]

 the output is null. I'm sure I'm missing something here, I just don't know 
 what.


 On Fri, 25 Jul 2008, Tomas Doran wrote:

 
  On 25 Jul 2008, at 14:50, James S. White wrote:
 
   I did. I want to use it as a variable even though it's passed in as
   an arg.
   I didn't mean to be unclear, sorry. Once it's stashed, can I use it
   like
   [% myarg %] in a template? or [% c.stash.myarg %]?
  
 
  Yes, either.
 
  Cheers
  t0m
 


 ___
 List: Catalyst@lists.scsys.co.uk
 Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
 Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
 Dev site: http://dev.catalyst.perl.org/



___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Using a post argument in a template

2008-07-25 Thread J. Shirley
On Fri, Jul 25, 2008 at 8:02 AM, James S. White [EMAIL PROTECTED] wrote:
 nevermind. this works. I am an idiot. It helps if the array isn't empty...

 On Fri, 25 Jul 2008, James S. White wrote:

 I can stash and array and when I use [% c.stash.mylist %] in the template,
 it prints 'ARRAY(0x94023b0)' but if I try:

 [% FOREACH element IN c.stash.mylist %]
 [% element %]
 [% END %]

 the output is null. I'm sure I'm missing something here, I just don't know 
 what.


You also don't need to use the c.stash prefix, [% mylist %] should
work for you.

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Using a post argument in a template

2008-07-24 Thread Eden Cardim
On Fri, Jul 25, 2008 at 1:12 AM, James S. White [EMAIL PROTECTED] wrote:
 I'm passing an argument to the method via a post, and then catch it with
 my ( $self, $c, $myarg ) = @_; shouldn't there be a way to mine it without
 using [% c.req.arguments.0 %] in the template?

 like [% c.controller('Page').methodname.myarg %] or something...

You want [% c.req.body_params.myarg %] if it's a post, [%
c.req.params.myarg %] if you don't care. I would munge the parameters
in the controller and try to formalize an API to interact with the
view though. Also, avoid making your view-side code be
controller-dependent, you'll surely regret it later.

-- 
edenc.vox.com

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/