NAME
Catalyst::View::Template::Pure::Helpers - Simplify some boilerplate
SYNOPSIS
package MyApp::View::Story;
use Moose;
use Catalyst::View::Template::Pure::Helpers (':ALL');
extends 'Catalyst::View::Template::Pure';
has [qw/title body capture arg q/] => (is=>'ro', required=>1);
__PACKAGE__->config(
returns_status => [200],
template => q[
<!doctype html>
<html lang="en">
<head>
<title>Title Goes Here</title>
</head>
<body>
<a name="hello">hello</a>
</body>
</html>
],
directives => [
'a[name="hello"]@href' => Uri('Story.last',['={year}'], '={id}', {q=>'={q}',rows=>5}),
],
);
DESCRIPTION
Generates code for some common tasks you need to do in your templates, such as build URLs etc.
Uri
Used to generate a URL via $c->uri_for. Takes signatures like:
Uri("$controller.$action", \@captures, @args, \%query)
Uri(".$action", \@captures, @args, \%query)
Uri("$relative_action_private_name", \@captures, @args, \%query)
Uri("$absolute_action_private_name", \@captures, @args, \%query)
We fill placeholders in the arguments in the same was as in templates, for example:
Uri('Story.last',['={year}'], '={id}', {q=>'={q}',rows=>5})
Would fill year, id and q from the current data context. We also merge in the following keys to the current data context:
captures => $c->request->captures,
args => $c->request->args,
query => $c->request->query_parameters;
To make it easier to fill data from the current request. For example:
Uri('last', ['={captures}'], '={args}')
You can also use data paths placeholders to indicate the action on which we are building a URI:
Uri('={delete_link}', ['={captures}'], '={args}')
In this case the placeholder should refer to a Catalyst::Action object, not a string:
$c->view('List', delete_link => $self->action_for('item/delete'));
This may change in a future version.
- Uri("$controller.$action", \@captures, @args, \%query)
-
URI for an action at a specific Controller. '$controller' should be a controller namespace part, for example 'MyApp::Controller::User' would be 'User' and 'MyApp::Controller::User::Info' would be 'User::Info'.
- Uri(".$action", \@captures, @args, \%query)
-
Relative version of the previous helper. Set the controller to the current controller.
- Uri("$absolute_action_private_name", \@captures, @args, \%query)
-
Creates a URI for an absolute action namespace. Examples:
Uri('/root/user')
- Uri("$relative_action_private_name", \@captures, @args, \%query)
-
Creates a URI for a relative (under the current controller namespace) action namespace. Examples:
Uri('user/info')
Apply
Takes a view name and optionally arguments that are passed to ->new. Used to apply a view over the results of a previous one, allowing for chained views.
'ul.todo-list li' => {
'.<-tasks' => Apply('Summary::Task'),
},
Useful when you wish to delegate the job of processing a section of the template to a different view, but you don't need a full include.
Wrap
Used to pass the response on a template to another template, via a 'content' argument. Similar to the 'wrapper' processing instruction.
SEE ALSO
Template::Pure, Catalyst::View::Template::Pure
AUTHOR
John Napiorkowski L<email:jjnapiork@cpan.org>
COPYRIGHT & LICENSE
Please see Catalyst::View::Template::Pure> for copyright and license information.