Accessing Block Variables in concrete5

If you are developing a concrete5 block, then it is very likely that you are also saving data about your block in the database. Such data could be settings for each block instance. In that case, you would need to access that data from within the block’s controller or view scripts.

Let us assume that you have a column named title in your block’s database table. In this case, the current block instance’s value of that column can simply be accessed as a controller property like this:


// Inside your block's controller class
$blockTitle = $this->title;

In your view scripts, you can access your block attributes from variables of the same name. That is, you would be able to access the title attribute from before like shown below.


<!-- A block view script such as view.php -->
<h1><?php echo htmlentities($title); ?></h1>

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *