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

[5.x] Add depth parameter to flatten modifier #10187

Merged
merged 2 commits into from
May 23, 2024

Conversation

godismyjudge95
Copy link
Contributor

This PR passes through the a depth parameter to the underlying collect()->flatten($depth) call inside the flatten modifier. It still defaults to infinite if no depth is specified.

Example Data:

$input = [
    'ingredients' => [
        'spices' => ['garlic', 'cumin', 'ginger', 'turmeric', 'paprika', 'curry powder'],
        'vegetables' => ['tomatoes', 'onion'],
        'meat' => ['chicken'],
    ],
];

Example Template:

{{ data | flatten(1) | to_json }}

Example Output:

[
    ["garlic", "cumin", "ginger", "turmeric", "paprika", "curry powder"],
    ["tomatoes", "onion"],
    ["chicken"]
]

@jasonvarga jasonvarga merged commit 177ef90 into statamic:5.x May 23, 2024
16 checks passed
@godismyjudge95 godismyjudge95 deleted the add-flatten-modifier-depth branch May 24, 2024 00:40
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