Background color?
Permalink
Is there a way to create a custom block that allows you to change the background color of the entire block and/or a div within the block?
Add any jquery based colorpicker in the edit.php and then save the value to the database. And once you view the block you retrieve the data from the database and give it to the view.php. Below is a draft on what I mean:
db.xml
controller.php
I haven't checked this code, but it demonstrates how I would tackle the problem. The idea here is that when I pick the color (using the edit.php) I would make it part of a form and then just retreave the value by using the REQUEST php function. After that I would check it and add it to the blocks database. This is done automatically by the save function ("works only for the btTable"). Then I retreave it and use it in the view by writing $bgColor where ever I wan't the value to be used ($this->set creates php variables for the view.php).
db.xml
<?xml version="1.0"?> <schema version="0.3"> <table name="btTestBlock"> <field name="bID" type="I"> <key /> <unsigned /> </field> <field name="blockColor" type="X2"> </field> </table> </schema>
controller.php
<?php defined('C5_EXECUTE') or die("Access Denied."); class TestBlockController extends BlockController { protected $btTable = 'btTestBlock'; protected $btInterfaceWidth = "600"; protected $btInterfaceHeight = "465"; public function getBlockTypeDescription() { return t("Test block"); } public function getBlockTypeName() { return t("Gallery"); } function __construct($obj = null) { parent::__construct($obj); }
Viewing 15 lines of 33 lines. View entire code block.
I haven't checked this code, but it demonstrates how I would tackle the problem. The idea here is that when I pick the color (using the edit.php) I would make it part of a form and then just retreave the value by using the REQUEST php function. After that I would check it and add it to the blocks database. This is done automatically by the save function ("works only for the btTable"). Then I retreave it and use it in the view by writing $bgColor where ever I wan't the value to be used ($this->set creates php variables for the view.php).
<div style="background-color: <?php echo $bgcolor;?>;">Blah</div>
You can check out my block to see how the color picker works.http://www.concrete5.org/marketplace/addons/search-highlighter/...