Skip to content

Commit

Permalink
Added __odd__, __even__, __first__, __last__ and __counter__ to <mt:E…
Browse files Browse the repository at this point in the history
…ntryCategories>. I verified that it works with the following template:

<mt:Entries>

<mt:EntryCategories>
<mt:If name="__first__">
First!
</mt:If>
<mt:If name="__last__">
Last!
</mt:If>
<mt:If name="__odd__">
<$mt:var name="__counter__"$> is odd!
</mt:If>
<mt:If name="__even__">
<$mt:var name="__counter__"$> is even!
</mt:If>
<$mt:CategoryLabel$><br/>
</mt:EntryCategories>
</mt:Entries>

</mt:Entries>
  • Loading branch information
MikeThomsen authored and byrnereese committed Jun 28, 2010
1 parent 726e7a3 commit f2ff752
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/MT/Template/ContextHandlers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9918,12 +9918,23 @@ sub _hdlr_entry_categories {
my $res = '';
my $glue = $args->{glue};
local $ctx->{inside_mt_categories} = 1;

my $cnt = 1;
my $vars = $ctx->{__stash}{vars} ||= {};

for my $cat (@$cats) {
local $ctx->{__stash}->{category} = $cat;
local $vars->{__first__} = ($cat == $cats->[0]);
local $vars->{__last__} = ($cat == $cats->[scalar(@$cats)-1]);
local $vars->{__odd__} = ($cnt % 2 ) == 1;
local $vars->{__even__} = ($cnt % 2 ) == 0;
local $vars->{__counter__} = $cnt;

defined(my $out = $builder->build($ctx, $tokens, $cond))
or return $ctx->error( $builder->errstr );
$res .= $glue if defined $glue && length($res) && length($out);
$res .= $out;
$cnt++;
}
$res;
}
Expand Down

0 comments on commit f2ff752

Please sign in to comment.