Christopher H. Laco > Mango-0.01000_13 > Mango::Catalyst::View::Template

Download:
Mango-0.01000_13.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source  

NAME ^

Mango::Catalyst::View::Template - View class for template based output

SYNOPSIS ^

    $c->view('Template');

DESCRIPTION ^

Mango::Catalyst::View::Template renders content using one of the following supported Catalyst views:

    Catalyst::View::TT

and serves it with the content_type specified.

CONSTRUCTOR ^

new

Arguments: $c

Creates a new view for use in Catalyst.

ATTRIBUTES ^

The following method attribute are available:

Template

Arguments: $template

Sets the template to be used for the current action.

METHODS ^

content_type

Arguments: $content_type

Gets/sets the value of the Content-Type header to get sent with the rendered output.

    $self->content_type('text/html');

process

Renders content using the specified view_class and sets the content_type.

share_paths

Arguments: \@paths

Gets/sets the list of paths in the share containing templates for the current view.

    $self->share_paths([
        '/share/templates',
        '/share/other/templates'
    ]);

render

Arguments: $c, $name [, \%vars]

Calls render on the template instance.

    $self->render(
        $c,
        'template',
        {title => 'foo'}
    ]);

root_paths

Arguments: \@paths

Gets/sets the list of paths in the application root containing templates for the current view.

    $self->root_paths([
        'templates',
        'other/templates'
    ]);

template_paths

Arguments: \@paths

Gets/sets the aggregate list of paths in containing templates for the current view. By default, this will be (@root_paths, @share_paths).

    $self->template_paths([
        'templates',
        'other/templates'
        '/share/templates',
        '/share/other/templates'
    ]);

When process is called, the paths in template_paths will be send to the underlying view instance template search path.

view_class

Arguments: $view_class

Gets/sets the name of the view class to be used to render content. The default view class is Catalyst::View::TT.

    $self->view_class('Catalyst::View::TT');

An exception is thrown if the view class can not be loaded.

view_instance

Arguments: $view_instance

Gets/sets the instance of the view class to be used to render content.

Arguments: $wrapper

Gets/sets the name of the template wrapper to be used around rendered content.

    $self->wrapper('wrapper');

SUBCLASSING ^

Mango::Catalyst::View::Template is the base class for the Text/HTML/XHTML views in Mango. This view is not really meant to be used directly. In most cases, you can simply alter functionality by setting properties of your app specific view subclasses:

    MyApp::View::Text;
    use strict;
    use warnings;
    use base qw/Mango::Catalyst::Text/;
    
    __PACKAGE__->share('/alternate/share/path);
    __PACKAGE__->view_class('Catalyst::View::MicroMason');
    __PACKAGE__->template_paths([
        '/path/to/root/tempates/mason/components/text'
    ]);
    
    1;

Of course, you can always just roll your own view and use Catalyst::View::TT and the like directly.

TEMPLATES ^

When a new instance of the view_class is created, it is given the list of template paths in template_paths in which to search for template files.

If <template_paths> is not already defined, the following directories are added in the following order:

    $c->path_to('root')/root_paths
    $c->share/share_paths

If the paths have '%view' in them, that will be replace with the short name of the specified view_class:

    $self->view_class('Catalyst::View::TT');
    'templates/%view/text' becomes 'templates/tt/text'
    
    $self->view_class('Catalyst::View::Mason');
    'templates/%view/text' becomes 'templates/mason/text'
    
    $self->view_class('Catalyst::View::HTML::Template');
    'templates/%view/text' becomes 'templates/html-template/text'

AUTHOR ^

    Christopher H. Laco
    CPAN ID: CLACO
    claco@chrislaco.com
    http://today.icantfocus.com/blog/
syntax highlighting: