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

Ability to use arrays in templates #11237

Closed
emteknetnz opened this issue May 14, 2024 · 0 comments
Closed

Ability to use arrays in templates #11237

emteknetnz opened this issue May 14, 2024 · 0 comments

Comments

@emteknetnz
Copy link
Member

emteknetnz commented May 14, 2024

Related to #11196

In this comment it was noted converting arrays to ArrayList at the template level is hard

This PR does do it, though it's done within ViewableData::obj(), which was considered to be a bit too risky

Options provided were:

  1. Update ViewableData::obj() to return arrays directly if there are any
  2. Update ViewableData::obj() to wrap arrays in either a list or ArrayData depending on what type of array they are
  3. Update ArrayList to either never wrap arrays, or to always wrap them in either a list or ArrayData depending on what type of array they are
  4. Some combination of the above
  5. Decoupling the logic from ViewableData - though that may be more effort than it's worth
  6. Something else neither of us considered yet, if someone else has any ideas.

Acceptance criteria

  • Native arrays can be returned in PHP methods, and then iterated over in templates
  • Nested arrays can be iterated over at all levels
  • Changes outside the templating system are kept to a minimum
  • Changes outside the templating system are evaluated to see how wide-reaching their affect might be, and the changelog mentions anything worth mentioning
  • Associative array can be access via their keys.

PRs

kitchen sink CI run with the main framework PR installed (note the one CI failure is just because pulls/6/arrays-in-templates isn't identified as matching a supported version of Silverstripe CMS - it's only failing because we are using a fork in CI)

Alternate PR

@maxime-rainville maxime-rainville added this to the Silverstripe CMS 6 milestone May 14, 2024
@GuySartorelli GuySartorelli self-assigned this May 16, 2024
@GuySartorelli GuySartorelli removed their assignment May 17, 2024
@GuySartorelli GuySartorelli removed their assignment May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants