silverstripe / silverstripe-framework

Silverstripe Framework, the MVC framework that powers Silverstripe CMS
https://www.silverstripe.org
BSD 3-Clause "New" or "Revised" License
720 stars 820 forks source link

Ability to use arrays in templates #11237

Closed emteknetnz closed 1 month ago

emteknetnz commented 1 month ago

Related to https://github.com/silverstripe/silverstripe-framework/issues/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

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