building-blocktypes
npx machina-cli add skill MacareuxDigital/concretecms-skills/building-blocktypes --openclawBuilding Block Types
Block types are the fundamental units of content in Concrete CMS. They allow users to add different types of content (text, images, forms, etc.) to pages.
Basic Workflow for Block Type Development
- Define the Block Type Directory:
- If in a package:
packages/your_package/blocks/block_handle/ - If in application:
application/blocks/block_handle/
- If in a package:
- Create the Controller:
- Create
controller.phpin the block directory.
- Create
- Create the View:
- Create
view.phpfor the public output.
- Create
- Create Add/Edit Forms:
- Create
add.phpandedit.phpfor the dashboard interface.
- Create
- Define Database Schema:
- Create
db.xml(Doctrine XML format) to define the block's data table. - Refer to the
working-with-databaseskill for the XML format.
- Create
- Register the Block Type:
- Install via Dashboard or programmatically in a package
install()method.
- Install via Dashboard or programmatically in a package
Reference Documentation
Source
git clone https://github.com/MacareuxDigital/concretecms-skills/blob/main/building-blocktypes/SKILL.mdView on GitHub Overview
Block types are the fundamental units of content in Concrete CMS, letting editors add text, images, forms, and other content to pages. This skill covers creating and modifying custom block types, including directory structure, controllers, views, add/edit forms, and database schemas, plus how to register and install them.
How This Skill Works
Create the block type under a package or application directory, then build controller.php and view.php for output, add.php and edit.php for the dashboard UI, and define the data model in db.xml using Doctrine XML. Finally, register the block type so it can be installed via the Dashboard or programmatically in the package install() method.
When to Use It
- You need a custom content block (e.g., testimonials, image gallery) that editors can place on pages.
- You want to modify how a block type collects data by updating its add/edit forms.
- You’re packaging a custom block type for reuse across sites via a package.
- You must define the block's data schema using Doctrine XML in db.xml.
- You want to install or register a new block type through the Dashboard or a package install() method.
Quick Start
- Step 1: Create the block directory under packages/your_package/blocks/block_handle/ or application/blocks/block_handle/.
- Step 2: Add controller.php and view.php to define output and behavior.
- Step 3: Create add.php, edit.php, and db.xml, then install the block type via the Dashboard or package install() method.
Best Practices
- Organize the block type under the appropriate directory: packages/your_package/blocks/block_handle/ or application/blocks/block_handle/.
- Keep a clear block_handle and match file names: controller.php, view.php, add.php, edit.php, db.xml.
- Define the data model in db.xml using Doctrine XML format per the guidelines.
- Test installation and rendering in a staging site before production.
- Document dependencies and references (Form Widgets, Pagerfanta) in your block's docs.
Example Use Cases
- Testimonial block that displays client quotes with rotation
- Image gallery block with thumbnails and lightbox
- Newsletter signup form block integrated into a page
- Product features block with icons and toggles
- CTA block customized per page context