GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  CATALYST::VIEW::TEMPLATE::DECLARE (3)

.ds Aq ’

NAME

Catalyst::View::Template::Declare - Use Template::Declare with Catalyst

CONTENTS

VERSION

Version 0.02

SYNOPSIS

Create the view:



     myapp_create.pl view TD Template::Declare



Add templates in MyApp::View::TD::<name>:



     package MyApp::View::TD::Test;
     use Template::Declare::Tags;

     template foo => sub { html {} };
     template bar => sub {   ...   };
     1;



Then use the templates from your application:



     $c->view(TD)->template(foo);
     $c->detach(View::TD);



The Catalyst context is passed as the second agument to the templates:



     template foo => sub {
         my ($self, $c) = @_;
         return This is the . $c->action.  action.;
     };



The Catalyst stash is passed as the third argument, but is also available via the glocal $_ variable for the duration of the template:



     template bar => sub {
         return "Hello, $_{world}";
     };



Have fun. This is all somewhat experimental and subject to change.

DESCRIPTION

Make a view:



    package MyApp::View::TD;
    use base Catalyst::View::Template::Declare;
    1;



Make a template:



    package MyApp::View::TD::Root;
    use Template::Declare::Tags;

    template foo => sub {
        my ($self, $c) = @_;
        html {
            head { title { $c->stash->{title} } };
            body { "Hello, world" }
          }
    };



In your app:



    $c->view(TD)->template(foo);
    $c->stash(title => test);
    $c->detach(View::TD);



And get the output:



    <html><head><title>test</title></head><body>Hello, world</body></html>



You can spread your templates out over multiple files. If your view is called MyApp::View::TD, then everything in MyApp::View::TD::* will be included and templates declared in those files will be available as though they were declared in your main view class.

Example:



    package MyApp::View::TD::Foo;
    use Template::Declare::Tags;
    template bar => sub { ... };
    1;



Then you can set $c->view(TD)->template(bar) and everything will work as you expect.

The arguments passed to the templates are:
$self The object or package name in which the template is defined.
$c The Catalyst context object.
$stash A copy of the Catalyst stash, also available via $_. Modifications to this copy of the stash will have no effect on the contents of $c->stash.
$args Any arguments passed to render().
For those stuck with a version of Template::Declare older then 0.26, no arguments will be passed to the templates. But you can still use the otherwise-deprecated c package to get at the Catalyst context:



    template bar => sub { "Hello, ". c->stash->{world} };



METHODS

    process

Render the template in $self->template; see Catalyst::View::Templated for information on how to specify the template.

render($template, CW@args)

Render the template named by $template and return the output.

    COMPONENT

Not for you.

AUTHOR

Jonathan Rockway, <jrockway at cpan.org>

BUGS

Please report any bugs or feature requests to bug-catalyst-view-template-declare at rt.cpan.org, or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-View-Template-Declare>. I will be notified, and then you’ll automatically be notified of progress on your bug as I make changes.

SUPPORT

Visit #catalyst on irc.perl.org, submit an RT ticket, or send me an e-mail.

The git repository is at <http://git.jrock.us/>.

SEE ALSO

Catalyst::View::Templated

ACKNOWLEDGEMENTS

Template::Declare

Jifty

COPYRIGHT & LICENSE

Copyright 2007 Jonathan Rockway, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 CATALYST::VIEW::TEMPLATE::DECLARE (3) 2008-08-07

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.