Blocks

Blocks should be a familiar concept to any Concrete5 user. Blocks are great for editing simple content features. Concrete5 provides a great selection of default blocks. Chisel takes blocks to the next level by allowing the creation of custom blocks.

Blocks can be created in the Chisel Workshop. Simply select the 'Block' type option, give it a name and add fields for each piece of data that should be collected.

 

Here is an example of what an 'Employee Profile' block may look like in the workshop:



Once created, adding the new block would yield an edit window like this:




Block Output


Chisel generates all of the files necessary to make your block functional. The files it generates will be located here: '/application/blocks/your_block'

In addition to the normal files required for all blocks, Chisel creates model classes for retrieveing your block's data. The block's model will already be instantiated in your block's view and assigned to a variable representative of your block's name. Methods for pulling each piece of data in your block have also already been defined and are generated based on the label assigned in the workshop. Below is an example of the basic 'view.php' file generated by Chisel that will illustrate how the models are pulling the data. For more information on models, click here.

The following view.php sample was generated from the examples above.

In this example, 'Empolyee Profile' is the name of our block.

A variable, $employeeProfile, has already been defined as our block's model.

A method has been created for pulling each piece of data, some of which contain base logic:

  • $employeeProfile->getName()
  • $employeeProfile->getPosition()
  • $employeeProfile->getPhoto(600,600)
  • $employeeProfile->getPhone()
  • $employeeProfile->getEmail()

Notice the two parameters passed into the getPhoto method. Some field types methods come with some base logic for convenience. This image field type method is set up to return an image object and requests the maximum image dimensions for your selected photo, in this case 600 x 600. There is also an optional third 'crop' parameter that is false by default.



Using AJAX in your block


For more advance Chisel blocks, you may want to add some AJAX methods that call back to your block's controller.

AJAX methods must be registered in your block's controller.php file. To do so, add the following property with the names of each method you wish to be accessible via an AJAX call.

protected $ajaxMethods = array(\'my_ajax_method\',\'my_other_ajax_method\');


Once registered, you can retrieve the path by calling the following method from the controller object in your view.php file.

$controller->getAjaxPath(\'my_ajax_method\');