Accessing Block Variables in concrete5

Published on October 26, 2012 by

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>
Author avatar
Bo Andersen

About the Author

I am a back-end web developer with a passion for open source technologies. I have been a PHP developer for many years, and also have experience with Java and Spring Framework. I currently work full time as a lead developer. Apart from that, I also spend time on making online courses, so be sure to check those out!

Leave a Reply

Your e-mail address will not be published.