Inject code once in a page from a block

Permalink
Hi !

I use the same custom block more the once in a view. Every block have the same css code to display so I have the same css code many times in the page.

So I have two questions :-)

1) How can I check if a block is used in another area on the page?

2) Can I inject the css code one time into the page from a block view?

Thanks,
Willy

wguggen
 
ryan replied on at Permalink Reply
ryan
Check out this page in the docs:
http://www.concrete5.org/documentation/developers/blocks/mvc-approa...

you'd add something like this to your block controller
public function on_page_view() {
  $html = Loader::helper('html');
  $this->addHeaderItem($html->css('your.css')));
}


That adds the css code to array of items to be added to the header. Before they're inserted int the header it's run through array_unique and the css is inserted only once even if that block is rendered multiple times.
wguggen replied on at Permalink Reply
wguggen
Thanks, I love concrete5 :-)

Where must I place my cc file in the block directory structure?

Thanks a lot