Add Block Type to Package

The best way we can install this block type is to add it to the CIF XML that we used earlier to install the Dreamrs page theme. Then, we can increment the version number on the package, update the package, and the block type will automatically be installed (and mapped to the Dreamrs package.)

Create a blocks.xml File

Since this is a block type (and we know we’ll eventually need to make more of them, let’s create a new CIF XML file within our Dreamrs package for block types. Within packages/dreamrs/install/, copy the `theme.xml’ file to ‘block_types.xml’:

cp themes.xml block_types.xml

Next, edit the file. Remove the <themes> node and replace it with one that installs a block type and attaches it to the dreamrs package. This should be the final contents of this file when we’re done:

<?xml version="1.0"?>
<concrete5-cif version="1.0">
    <blocktype handle="page_header" package="dreamrs"/>

Modify the install() and upgrade() methods

The install() and upgrade() methods in our package currently install the theme.xml content file, but we’ve added a new file for block types. Let’s add that to the method. Open up packages/dreamrs/controller.php and make these changes:

public function install()

public function upgrade()

Upgrade the Package

Finally, let’s upgrade the package. Increment the $pkgVersion property in the controller.php file to 0.6.1. Then, upgrade the package. You can upgrade it from the Dashboard, or the command line. I prefer the command line -- it’s quicker. From within the public/ directory the dreamrs package, type:

concrete/bin/concrete5 c5:package:update dreamrs

That’s it! Let’s check out blocks list. In the Dashboard, browse to Dashboard > Stacks & Blocks > Block Types. There’s our block:

It’s also ready to be placed from the Add Block panel:

If we check the database we can also verify that our custom database table is present:

Now let’s make it work.

Loading Conversation