CGI-Application-Plugin-AnyTemplate

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN


    Note that the API has changed for version 0.10 in a
    non-backwards-compatible way in order to use the new hook system
    provided by recent versions of "CGI::Application".

  The load_tmpl hook
    The "load_tmpl" hook is designed to be compatible with the "load_tmpl"
    hook defined by "CGI::Application" itself.

    The "load_tmpl" hook is called before the template object is created.
    Any callbacks that you register to this hook will be called before each
    template is loaded. Register a "load_tmpl" callback with:

       $self->add_callback('load_tmpl',\&my_load_tmpl);

    When the "load_tmpl" callback is executed it will be passed three
    arguments (*adapted from the* CGI::Application *docs*):

     1. A hash reference of the extra params passed into C<load_tmpl>
        (ignored by AnyTemplate with the exception of 'path')

README  view on Meta::CPAN

    The "path" param of $ht_params is initially set to the value of
    "add_include_paths" (if set). Your callback can modify the "path" param,
    and "add_include_param" will be set to the result.

    Plugin authors who want to provide template processing features are
    encouraged to use the 'load_tmpl' hook when possible, since it will work
    both with AnyTemplate and with CGI::Application's built-in "load_tmpl".

  The template_pre_process and template_post_process hooks
    Before the template output is generated, the "template_pre_process" hook
    is called. Any callbacks that you register to this hook will be called
    before each template is processed. Register a "template_pre_process"
    callback as follows:

        $self->add_callback('template_pre_process', \&my_tmpl_pre_process);

    Pre-process callbacks will be passed a reference to the $template
    object, and can can modify the parameters passed into the template by
    using the "param" method:

        sub my_tmpl_pre_process {
            my ($self, $template) = @_;

            # Change the internal template parameters by reference
            my $params = $template->get_param_hash;

            foreach my $key (keys %$params) {

README  view on Meta::CPAN

            $template->param('foo', 'bar');

        }

    After the template output is generated, the "template_post_process" hook
    is called. You can register a "template_post_process" callback as
    follows:

        $self->add_callback('template_post_process', \&my_tmpl_post_process);

    Any callbacks that you register to this hook will be called after each
    template is processed, and will be passed both a reference to the
    template object and a reference to the output generated by the template.
    This allows you to modify the output of the template:

        sub my_tmpl_post_process {
            my ($self, $template, $output_ref) = @_;

            $$output_ref =~ s/foo/bar/;
        }

lib/CGI/Application/Plugin/AnyTemplate.pm  view on Meta::CPAN

Note that the API has changed for version 0.10 in a
non-backwards-compatible way in order to use the new hook system
provided by recent versions of C<CGI::Application>.

=head2 The load_tmpl hook

The C<load_tmpl> hook is designed to be compatible with the C<load_tmpl>
hook defined by C<CGI::Application> itself.

The C<load_tmpl> hook is called before the template object is created.
Any callbacks that you register to this hook will be called before each
template is loaded.  Register a C<load_tmpl> callback with:

   $self->add_callback('load_tmpl',\&my_load_tmpl);

When the C<load_tmpl> callback is executed it will be passed three
arguments (I<adapted from the> L<CGI::Application> I<docs>):

 1. A hash reference of the extra params passed into C<load_tmpl>
    (ignored by AnyTemplate with the exception of 'path')

lib/CGI/Application/Plugin/AnyTemplate.pm  view on Meta::CPAN

param, and C<add_include_param> will be set to the result.

Plugin authors who want to provide template processing features are
encouraged to use the 'load_tmpl' hook when possible, since it will work
both with AnyTemplate and with L<CGI::Application>'s built-in
C<load_tmpl>.

=head2 The template_pre_process and template_post_process hooks

Before the template output is generated, the C<< template_pre_process >>
hook is called.  Any callbacks that you register to this hook will be
called before each template is processed.  Register a
C<template_pre_process> callback as follows:

    $self->add_callback('template_pre_process', \&my_tmpl_pre_process);

Pre-process callbacks will be passed a reference to the C<$template>
object, and can can modify the parameters passed into the template by
using the C<param> method:

    sub my_tmpl_pre_process {
        my ($self, $template) = @_;

        # Change the internal template parameters by reference
        my $params = $template->get_param_hash;

        foreach my $key (keys %$params) {

lib/CGI/Application/Plugin/AnyTemplate.pm  view on Meta::CPAN

        $template->param('foo', 'bar');

    }


After the template output is generated, the C<template_post_process> hook is called.
You can register a C<template_post_process> callback as follows:

    $self->add_callback('template_post_process', \&my_tmpl_post_process);

Any callbacks that you register to this hook will be called after each
template is processed, and will be passed both a reference to the
template object and a reference to the output generated by the template.
This allows you to modify the output of the template:

    sub my_tmpl_post_process {
        my ($self, $template, $output_ref) = @_;

        $$output_ref =~ s/foo/bar/;
    }

lib/CGI/Application/Plugin/AnyTemplate/Base.pm  view on Meta::CPAN


Returns the template with all the values filled in.

    return $template->output();

You can also supply names and values to the template at this stage:

    return $template->output('name' => 'value', 'name2' => 'value2');

Before the template output is generated, the C<< template_pre_process >>
hook is called.  Any callbacks that you register to this hook will be
called before each template is processed.  Register a
C<template_pre_process> callback as follows:

    $self->add_callback('template_pre_process', \&my_tmpl_pre_process);

Pre-process callbacks will be passed a reference to the C<$template>
object, and can can modify the parameters passed into the template by
using the C<param> method:

    sub my_tmpl_pre_process {
        my ($self, $template) = @_;

        # Change the internal template parameters by reference
        my $params = $template->get_param_hash;

        foreach my $key (keys %$params) {

lib/CGI/Application/Plugin/AnyTemplate/Base.pm  view on Meta::CPAN

        $template->param('foo', 'bar');

    }


After the template output is generated, the C<template_post_process> hook is called.
You can register a C<template_post_process> callback as follows:

    $self->add_callback('template_post_process', \&my_tmpl_post_process);

Any callbacks that you register to this hook will be called after each
template is processed, and will be passed both a reference to the
template object and a reference to the output generated by the template.
This allows you to modify the output of the template:

    sub my_tmpl_post_process {
        my ($self, $template, $output_ref) = @_;

        $$output_ref =~ s/foo/bar/;
    }



( run in 0.502 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )