Skip to content

Instantly share code, notes, and snippets.

@colinjoy
Created August 26, 2015 07:01
Show Gist options
  • Save colinjoy/8cdd8b68c5e8afaefeb4 to your computer and use it in GitHub Desktop.
Save colinjoy/8cdd8b68c5e8afaefeb4 to your computer and use it in GitHub Desktop.
Add some contextual classes to the <body> tag of bugzilla using hook template_before_process
sub template_before_process {
my ($self, $args) = @_;
my ($file, $vars) = @$args{qw(file vars)};
if($file eq 'global/header.html.tmpl') {
$vars->{bodyclasses} = [] unless ref($vars->{bodyclasses});
my $caller = $vars->{component}->{caller};
my @classes;
$caller =~ s/\.html\.tmpl//; # strip file extension
@classes = split('/', $caller); # use filepath segments as classes
$caller =~ s</><->g; # use full path as additional class
push @classes, $caller;
my @classes = keys %{{ map{ $_ => 1} @classes }}; # remove possible duplicates
push $vars->{bodyclasses}, sort @classes;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment