Skip to content

Commit

Permalink
DOC Document the current scope loop
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed May 17, 2024
1 parent 158c8ca commit c441d97
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions en/02_Developer_Guides/01_Templates/01_Syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,18 @@ page.
> This demonstrates the concept of scope ([see scope below](#scope)). When inside a `<% loop %>` the scope of the template has changed to the
> object that is being looped over.
You can also use `<% loop %>` without explicitly saying what to loop over. This will result in looping over whatever is currently in scope.

This can be particularly useful when you have collections within collections.

```ss
<% loop $MyLists %>
<% loop %>
This is looping over each of the collections that are contained inside the \$MyLists collection.
<% end_loop %>
<% end_loop %>
```

### Altering the list

`<% loop %>` statements often iterate over [`SS_List`](api:SilverStripe\ORM\SS_List) instances. As the template has access to the list object,
Expand Down
2 changes: 2 additions & 0 deletions en/08_Changelogs/5.3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ Passing a non-array `$fields` argument to both [`FieldList::addFieldsToTab()`](a

## Bug fixes

- If you use `<% loop %>` in your templates without telling it what to loop, previously the behaviour was to fail silently. This will now loop over what is currently in scope. See [looping over lists](/developer_guides/templates/syntax/#looping-over-lists) for more details.

This release includes a number of bug fixes to improve a broad range of areas. Check the change logs for full details of these fixes split by module. Thank you to the community members that helped contribute these fixes as part of the release!

### Sanitisation of HTML
Expand Down

0 comments on commit c441d97

Please sign in to comment.