Commit d7cf1c91 authored by Dylan William Hardison's avatar Dylan William Hardison Committed by Jeff Fearn

add a new hook: template_after_create (#60)

parent c31565fe
......@@ -1479,6 +1479,21 @@ look at the code for C<create> in L<Bugzilla::Template>.)
=back
=head2 template_after_create
This hook allows you to manipulate the Template object before it is used.
You can use this to define new vmethods or filters in extensions.
Params:
=over
=item C<template>
This is the L<Bugzilla::Template> object.
=back
=head2 template_before_process
This hook is called any time Bugzilla processes a template file, including
......
......@@ -1186,6 +1186,7 @@ sub create {
Bugzilla::Hook::process('template_before_create', { config => $config });
my $template = $class->new($config)
|| die("Template creation failed: " . $class->error());
Bugzilla::Hook::process('template_after_create', { template => $template });
# Pass on our current language to any template hooks or inner templates
# called by this Template object.
......
......@@ -920,6 +920,19 @@ sub template_before_create {
$config->{VARIABLES}->{example_global_variable} = sub { return 'value' };
}
sub template_after_create {
my ( $self, $args ) = @_;
my $context = $args->{template}->context;
# define a pluck method on template toolkit lists.
$context->define_vmethod(
list => pluck => sub {
my ( $list, $field ) = @_;
return [ map { $_->$field } @$list ];
}
);
}
sub template_before_process {
my ($self, $args) = @_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment