Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC Document ability to loop over arrays in templates #517

Merged

Conversation

GuySartorelli
Copy link
Member

Copy link
Member

@emteknetnz emteknetnz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should make your recommended changes

@GuySartorelli
Copy link
Member Author

Made the changes and rebased to resolve the conflict

@GuySartorelli GuySartorelli force-pushed the pulls/6/loop-over-arrays branch from 61664da to bc25f02 Compare May 22, 2024 22:40
@@ -33,6 +33,9 @@ CanonicalURLMiddleware::singleton()->setEnabledEnvs([

### Other new features

- Native indexed PHP arrays can now be passed into templates and iterated over with `<% loop $MyArray %>`. Under the hood they are wrapped in [`ArrayList`](api:SilverStripe\View\ViewableData), so you can get the count using `$Count` and use `<% if $ArrayList %>` as a shortcut for `<% if $ArrayList.Count %>`. Other functionality from `ArrayList` such as filtering and sorting cannot be used on arrays since they don't have keys to filter or sort against.
- Note that associative arrays will continue to be wrapped in `ArrayData`, which means you can access their values by key but may not be able to iterate over them.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Note that associative arrays will continue to be wrapped in `ArrayData`, which means you can access their values by key but may not be able to iterate over them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are still wrapped if they're nested in an array/ArrayList - but you can't return them directly from a controller. I'm not sure if it's even worth mentioning assoc arrays here because their usage is inconsistent and confusing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not worth mentioning, since the work to deal with those was split out into silverstripe/silverstripe-framework#11262

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@GuySartorelli GuySartorelli force-pushed the pulls/6/loop-over-arrays branch from bc25f02 to 800b318 Compare May 24, 2024 01:47
@emteknetnz emteknetnz merged commit 72d0ed5 into silverstripe:6 May 24, 2024
3 checks passed
@emteknetnz emteknetnz deleted the pulls/6/loop-over-arrays branch May 24, 2024 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants