Skip to content

Commit

Permalink
[#641 state:resolved] Fixed an error which caused the widgetset loop …
Browse files Browse the repository at this point in the history
…tag to misbehave with the last widget.
  • Loading branch information
MikeThomsen committed Dec 5, 2010
1 parent cf60cfe commit 789fd31
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/MT/Template/ContextHandlers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22031,19 +22031,21 @@ sub _hdlr_widget_loop {
$ctx->stash('widgetset', $tmpl);
local $vars->{__size__} = scalar(@selected);
my $glue = $args->{glue} || '';
for (my $index = 0; $index <= $#selected; $index++) {
my $size = scalar(@selected);
for (my $index = 0; $index < $size; $index++) {
my $widget = MT->model('template')->load({ id => $selected[$index] });
local $vars->{__first__} = ($index == 0);
local $vars->{__last__} = ($index == $#selected-1);
local $vars->{__last__} = ($index == ($size-1));
local $vars->{__index__} = $index;
local $vars->{__odd__} = $index % 2 == 1;
local $vars->{__even__} = $index % 2 == 0;
$ctx->stash('widget', $widget);
my $res = $builder->build($ctx, $tokens, $cond);
return $ctx->error($builder->errstr) unless defined $res;

$out .= ($index < $#selected and $glue ? sprintf('%s%s', $res, $glue) : $res);
$res .= $glue if ($glue && $index < $size - 1);
$out .= $res;
}


$ctx->stash('widgeset', undef);

Expand Down

0 comments on commit 789fd31

Please sign in to comment.