Controller create the needed stacks

Permalink 1 user found helpful
I want to create couple of stacks during installation of theme, when someone install theme, controller.php creates needed stacks during package installation.

Is this possible? Do anyone do such thing?

Thanks in advance...

 
jordanlev replied on at Permalink Reply
jordanlev
Creating empty stacks is easy:
Stack::addStack('Your Stack Name');


If you want to add blocks to the stacks, do so like this:
$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);

The specific fields and data for each block depends on what the blocktype is -- look at the block's db.xml file to see what fields it has.

Good luck!

-Jordan
psd2concrete5 replied on at Permalink Reply
Hello jordanlev,

Thanks for the reply it really works but when I install it create stack and
after uninstall theme and when attempting reinstall theme its create
duplicate stacks.
On Aug 29, 2014 1:09 AM, "concrete5 Community" <discussions@concretecms.com>
wrote:
hostco replied on at Permalink Best Answer Reply
hostco
To avoid a duplicate stack you can use this

$stack = Stack::getOrCreateGlobalArea('Your Stack Name');
jordanlev replied on at Permalink Reply
jordanlev
This is incorrect -- this will create a Global Area, which is not what the OP is asking about -- they only want to create a normal Stack.

Instead, you will need to check for the existence of the stack yourself first, like so:
$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);
}


-Jordan
hostco replied on at Permalink Reply
hostco
I stand corrected.

Thank you for clarifying Jordan.
psd2concrete5 replied on at Permalink Reply
Thank Host Co,For the reply, it is useful when i need to create global stack...

Thanks Jordan, i got what i want with your answer. and Host co.' tip is also useful to me. Thanks both of you..

Regards,
Rajesh
psd2concrete5 replied on at Permalink Reply
For 5.7
I added
use Stack;
But it didn't work. Do you have suggestions for this?