This is the documentation for concrete5 version 5.6 and earlier. View Current Documentation

A block's directory can contain the following items.

A Database Definition

db.xml

This is a file named db.xml, in the ADODB AXMLS format (link). This file describes the schema of the block in a way that can be easily read and understood. The schema can also be altered later and refreshed through the dashboard. Here is the schema for the Youtube Video block.

	<?xml version="1.0"?>
<schema version="0.3">
<table name="btYouTube">
<field name="bID" type="I">
<key />
<unsigned />
</field>
<field name="title" type="C" size="255"></field>
<field name="videoURL" type="C" size="255"></field>
</table>
</schema>

Multiple tables can contained within this file. The only requirement for the table is that the core block type table must contain a column named bID, which is an unsigned integer.

An Icon

icon.png

A block's icon is displayed in the Add Block window. This is a 16x16 PNG named "icon.png".

Controller

controller.php

This file extends the BlockController object. You can learn more about this file in the _MVC Approach_ (link) section of the Blocks Documentation

Core Templates

add.php

This file is rendered when the block is added.

edit.php

This file is rendered when the block is edited.

view.php

This file is rendered when the block is viewed in a page.

scrapbook.php (optional)

An optional file that is rendered when the block is displayed within the scrapbook.

Stylesheets, JavaScript and Other Assets

The following named items will be automatically added to a page's header, if the block in question has been added to that page:

  • view.css
  • view.js

Additionally, this behavior also applies to any files of any name within the following directories, should they exist:

  • css/
  • js/

auto.js

This file will be automatically loaded when the block is placed in add or edit moe.

Custom View Templates

If a a block's directory contains a directory named templates/ any .php files found in there will considered custom view templates for the block, and will be available in the "Set Custom Template" dialog box.

The Auto-Nav includes two such custom templates:

	templates/breadcrumb.php 	templates/header_menu.php

Auto-Loading JavaScript and CSS for Custom Templates

Additionally, custom templates may specify their own JavaScript and CSS, just like the main view template can.

The following custom template will load a custom stylesheet, a custom JavaScript file, in addition to the custom .php file.

	templates/special_menu/view.php 	templates/special_menu/view.js 	templates/special_menu/view.css

In this case, "Special Menu" will display as the available custom template, when accessing the Set Custom Template dialog box for this block type.

Tools

Finally, blocks can contain auxiliary files which we refer to as tools. Tools are typically chromeless scripts that will need to be run for a certain purpose (typically, AJAX loading, etc...) An example of this is the Page List's RSS feed, which is a custom tool.

Referencing the Tool

The page list's view template includes the following code:

	$rssUrl = $controller->getRssUrl($b);
?>
<div class="rssIcon">
<a href="<?=$rssUrl?>" target="_blank"><img src="<?=$uh->getBlockTypeAssetsURL($bt, 'rss.png')?>" width="14" height="14" /></a>

</div>
<link href="<?=$rssUrl?>" rel="alternate" type="application/rss+xml" title="<?=$controller->rssTitle?>" />

This code runs a custom function contained in the controller:

		public function getRssUrl($b){ 			$uh = Loader::helper('concrete/urls'); 			if(!$b) return ''; 			$btID = $b->getBlockTypeID(); 			$bt = BlockType::getByID($btID); 			$c = $b->getBlockCollectionObject(); 			$a = $b->getBlockAreaObject(); 			$rssUrl = $uh->getBlockTypeToolsURL($bt)."/rss?bID=".$b->getBlockID()."&cID=".$c->getCollectionID()."&arHandle=" . $a->getAreaHandle(); 			return $rssUrl; 		} 

The Tool

rss.php exists within the page list's tools/ directory. It is then passed the various arguments specified in the rssURL parameter.

Loading Conversation