How to add CSS for your block
If you develop your own block, you will probably need to use some css to properly style it. But the issue is that you can’t access the css file of the users theme (of course if you’re not developing the block for one specific project). However you can create and use custom css file for this specific block type.
Create and put css stylesheet file to the folder of your block. Let’s name it ‘style.css’ (it’s just an example)
After that, edit the ‘controller.php’ file of your block and add ‘on_page_view’ method.
public function on_page_view() { $bt = BlockType::getByHandle($this->btHandle); $uh = Loader::helper('concrete/urls'); $this->addHeaderItem('<link rel="stylesheet" type="text/css" href="'. $uh->getBlockTypeAssetsURL($bt, 'style.css') .'" />'); }
This will make concrete5 try to load style.css (if it exists) from your block folder on any pages that have your block.
Categories: concrete5 for developers