Created
August 26, 2015 07:01
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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