silverstripe / silverstripe-widgets

Widgets subsystem for Silverstripe CMS
http://silverstripe.org
BSD 3-Clause "New" or "Revised" License
38 stars 55 forks source link

WidgetHolder template seems to be clueless of loop figures #121

Closed lhasselb closed 8 years ago

lhasselb commented 8 years ago

If I am not wrong the WidgetHolder.ss template is used within the WidgetArea.ss template to wrap the Widgets added to a page: Here is the WidgetArea.ss

<% loop WidgetControllers %>
    $WidgetHolder
<% end_loop %>

and the WidgetHolder.ss:

<div class="WidgetHolder $ClassName<% if FirstLast %> $FirstLast<% end_if %>">
    <% if Title %><h3>$Title</h3><% end_if %>
    $Content
</div>

But if I add $Pos or $TotalItems to the latter the value for both position indicators is always 1 (for all Widgets added - I added 3). This came to my attention because the line

<% if FirstLast %> $FirstLast<% end_if %>

added "first last" every time (in my case for all 3 Widgets).

The documentation points out $FirstLast: Returns a string, "first", "last", "first last" (if both), or "". Useful for CSS classes.

If it is intended like that how should the logic for <% if FirstLast %> $FirstLast<% end_if %> work?

tractorcow commented 8 years ago

It's because the $WidgetHolder creates a new context, one where the current iterator is NOT available.

You need to add the iterator-specific variables into the top level template.

<% loop WidgetControllers %>
    <div class="<% if FirstLast %> $FirstLast<% end_if %>">
        $WidgetHolder
    </div>
<% end_loop %>