From c441d9728f4dac97e8337bb0470d780dce7fc4b6 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Fri, 17 May 2024 15:29:53 +1200 Subject: [PATCH] DOC Document the current scope loop --- en/02_Developer_Guides/01_Templates/01_Syntax.md | 12 ++++++++++++ en/08_Changelogs/5.3.0.md | 2 ++ 2 files changed, 14 insertions(+) diff --git a/en/02_Developer_Guides/01_Templates/01_Syntax.md b/en/02_Developer_Guides/01_Templates/01_Syntax.md index 5fd8e4900..97faf82d5 100644 --- a/en/02_Developer_Guides/01_Templates/01_Syntax.md +++ b/en/02_Developer_Guides/01_Templates/01_Syntax.md @@ -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, diff --git a/en/08_Changelogs/5.3.0.md b/en/08_Changelogs/5.3.0.md index 48f8ba4ee..a708d1932 100644 --- a/en/08_Changelogs/5.3.0.md +++ b/en/08_Changelogs/5.3.0.md @@ -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