1

I already discovered how to create a neo block programmatically from this post: How can I set a Neo field's values from my plugin/module?

However, I don't know how I can create a neo block with child blocks.

So the idea is I want something like this:

[
    'blocks' => [ // Neo field handle
        'new0' => [
            'modified' => 1,
            'type' => 'topLevel', // Top level neo block
            'enabled' => 1,
            'collapsed' => 0,
            'level' => 0,
            'fields' => [
                'someField' => true, // Neo block field
            ],
            'children' => [
                'new0' => [
                    'modified' => 1,
                    'type' => 'secondLevel', // child neo block
                    'enabled' => 1,
                    'collapsed' => 0,
                    'level' => 0,
                ]
            ]
        ]
    ]
]

The children array is just what I imagine the solution might be like. But this doesn't work.

Does anybody know how it should be done?

Thanks

2

I figured it out. You have to create a separate block and it somehow figures out it's a child based on the level you specify. So something like this:

[
    'new1' = [
        'modified' => 1,
        'type' => 'parentBlock',
        'enabled' => 1,
        'collapsed' => 0,
        'level' => 0,
        'fields' => [
            'theme' => 'black',
        ],
    ],
    'new2'= [
        'modified' => 1,
        'type' => 'childBlock',
        'enabled' => 1,
        'collapsed' => 0,
        'level' => 1, // increment the level
        'fields' => [
            'value' => 'text',
        ],
    ]
]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.