Getting not only the block data by ID but also its css

Permalink 1 user found helpful
In a view I can grab the data of any random block and display it like so:

$block = Block::getByID($bID);
$block->display($view = 'view', $args = array());


This gives me the data and the HTML of the block but it does not add the css or javascript that comes with the block.

How can I include e.g. the CSS as well?

Thx :-)

nerdess
 
glockops replied on at Permalink Reply
glockops
Try
$block->render('view');
nerdess replied on at Permalink Reply
nerdess
unfortunately render is not a method of block :-(
glockops replied on at Permalink Reply
glockops
Well it looks like it is not yet possible to do this through the API...

http://www.concrete5.org/developers/bugs/5-4-1-1/global-scrapbook-b...

Might check out the Global stacks/blocks options.

More Info:http://www.concrete5.org/community/forums/customizing_c5/global-sta...
nerdess replied on at Permalink Reply
nerdess
i found this which gives me objects that contain the js and css of a block. i can then add them to the header using $this->addHeaderItem(). it seems a bit clumsy though.

$b = Block::getByID(156);
$bvt = new BlockViewTemplate($b);
$headers = $bvt->getTemplateHeaderItems();
if (count($headers) > 0) { 
  foreach($headers as $h) {
   $this->addHeaderItem($h);
  }
}


ps: what annoys me massively is that I cannot use $this->addHeaderItem() inside the view() method of a controller......d'oh.
stephendmalloy replied on at Permalink Reply
stephendmalloy
@nerdess - I ran into this today. Were you able to find any other way? I'm pulling in blocks through a helper class in my theme files but I can't pull the CSS / JavaScript associated. It's not ideal for me to add header items through a controller given the strange dynamic behavior and requirements of the site I'm working on. If I recall, I can actually have controllers for me theme template files. Is this correct? Just wondering if there were any others ways.

Thanks!

This website stores cookies on your computer. These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media. To find out more about the cookies we use, see our Privacy Policy.