How to place a stack programmatically in an area on a page?
Permalink
Creating a stack with blocks inside follows this pattern:
But how do I place this new stack on a new page in an area f.e called 'MyArea'?
For a block, it would look like this:
How can I do the same with an already existing stack, that of course doesn't need any data to be passed, but simply needs to be copied into this example area called 'MyArea'?
$stack = Stack::getByName('Your Stack Name'); if (is_null($stack)) { $stack = Stack::addStack('Your Stack Name'); $block_type = BlockType::getByHandle('your_blocktype_handle'); $block_data = array( 'some_field_in_the_block' => 'Data you want to set for this field', 'some_other_field_in_the_block' => 'Other data for the other field', ); $stack->addBlock($block_type, STACKS_AREA_NAME, $block_data); }
But how do I place this new stack on a new page in an area f.e called 'MyArea'?
For a block, it would look like this:
$page_block = BlockType::getByHandle('MyHandle'); $block_data = array( 'data1' => $data1, 'data2' => $ptID, ); $NewBlock = $newPage->addBlock($page_block, 'MyArea', $block_data');
How can I do the same with an already existing stack, that of course doesn't need any data to be passed, but simply needs to be copied into this example area called 'MyArea'?
The following worked for me: