The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

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 arguements like:

    Uri("$controller.$action", \@captures, @args, \%query)

Basically if follows $c->uri_for, except the first argument must be a string with the target Controller 'dot' and action. You can use an action relative to the current controller by leave off the controller string (but the 'dot' in from the of the action is required.

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.

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.