Block styles not included when using block->display()
Permalink
I noticed that when inserting a block like this:
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?
public 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?
Thanks for this mainio. In regards to my PM's and to help others, in my case, i added the following to my on_page_view($page) function in my block controller to get the custom block styles:
(a bit of code borrowed from core_stack_display)
(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)); }
Thanks to you both! This is just what I'm looking for. :)
Glad it worked out for you. The snip above is now in use within my Enlil Genetic Stacks package available in the marketplace. PM me if either of you are interested in checking it out.
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