#Movable Type plugin MTRoundRobin # #Substitute a set of keywords into the template round-robin style. #There's no limit on the size of the space-separated set, and the #replacement can take place anywhere in the template, not just #once for each item in a loop. # #sample (alternates background colors for entry listing): # # #
# <$MTEntryTitle$>... #
#
use strict; use MT::Template::Context; MT::Template::Context->add_tag(RoundRobin => \&roundrobin); sub roundrobin { my ($ctx,$args) = @_; if ($args->{set}) { my @set = split(' ',$args->{set}); $ctx->stash('rr_set',\@set); $ctx->stash('rr_index',$#set); }else{ return undef unless $ctx->stash('rr_set'); my $set = $ctx->stash('rr_set'); my $i = $ctx->stash('rr_index'); $i = ++$i % @$set; $ctx->stash('rr_index',$i); return $set->[$i]; } ''; }