Handling the Adding of a Block
When a block type is dragged from the Add Panel onto a page, the following things occur:
If there is no
add.php
template, we automatically skip to step 5 (?) below.If the block does not support inline editing, a Concrete CMS dialog is displayed, set to the dimensions specified in the block controller's
$btInterfaceWidth
and$btInterfaceHeight
variables.If this block does support inline editing, the dialog is not displayed and editing begins within the page itself.
The
add()
method in the controller is run (if it exists) allowing any necessary data to be injected into the add template. Optional. If there are default parameters that the combined template uses, they can be set from within this method.The
add.php
template is rendered and returned to the browser. This content is injected either directly into the page (if inline editing is supported) or otherwise into the modal dialog.When the block is saved, the Controller's
validate()
method is run. If aConcrete\Core\Error\Error
object with errors is returned, these are displayed and the process terminates. Otherwise, thesave()
method is run.The completed block is rendered to the page (see Handling the Rendering of a Block below).
Handling the Editing of a Block
A block may be edited by clicking and choosing "Edit" from the menu. When this occurs, the following takes place:
The Controller's
edit()
method is run (if it exists), allowing any necessary data to be injected into the edit template.All database columns for this block (from the block's
$btTable
) are queried and automatically injected for use within the template.The
edit.php
file is rendered and returned to the browser.Variables from both the database and controller are available in the local scope, so if the
$btTable
has a column entitledcontent
you can simply do this in edit.php:<input type="text" name="content" value="<?= $content ?>">
When the block is saved, the server runs the same processes as when adding the block for the first time (see above).
The completed block is rendered to the page (see Handling the Rendering of a Block below).
Tip: Since the "add" and "edit" forms are usually extremely similar, you can avoid repetition by placing the code in edit.php
and simply include this from add.php
.
<?php $view->inc('edit.php') ?>
Handling the Rendering of a Block
When a block is rendered to a page (after being added/edited) the following things occur:
The Controller's
view()
method is run (if it exists), allowing any necessary data to be injected into the view template.All database columns for this block (from the block's
$btTable
) are queried and automatically injected for use within the template.The
view.php
file (or a custom template, if selected) is rendered.Variables from both the database and controller are available in the local scope, so if the
$btTable
has a column entitledcontent
you can simply do this inview.php
:<div class="ccm-block-type-custom-block-field"><?= $content ?></div>