Block styles not included when using block->display()
Permalinkpublic function view() { $stack = Stack::getByID(140); $block = $stack->getBlocks()[0]; $this->set('block', $block->display()); }
Then the block styles added by clicking on the block and selecting 'Design' aren't added to the block. If adding the stack to a page normally, they are. Anyone know how to include those block styles programmatically?
(a bit of code borrowed from core_stack_display)
$blocks = $stack->getBlocks(); foreach($blocks as $b) { $btc = $b->getInstance(); if('Controller' != get_class($btc)){ $btc->outputAutoHeaderItems(); } $csr = $b->getBlockCustomStyleRule(); if (is_object($csr)) { $styleHeader = '#'.$csr->getCustomStyleRuleCSSID(1).' {'. $csr->getCustomStyleRuleText(). "} \r\n"; $btc->addHeaderItem("<style type=\"text/css\"> \r\n".$styleHeader.'</style>', 'VIEW'); } $btc->runTask('on_page_view', array($page)); }
This needs to be in your controller's "on_start" (for single pages) or "on_page_view" (fo blocks) method.
And to wrap the correct CSS classes/id around the block area (so that the styles get applied), do something similar to this file:
/concrete/elements/block_area_header_view.php