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?

stephmars
 
LucasAnderson replied on at Permalink Reply
LucasAnderson
Sure, Concrete5 includes a color picker helper for adding/editing blocks. You can use this to pick a color in your custom block, and then output that color in the view.php via an inline style.

<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/...
sebmel replied on at Permalink Reply
sebmel
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
<?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);
      }


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).