Concrete 5.7 : creating a PageTheme class for a package’s Theme

Concrete 5.7 is completely different compared to 5.6. One of the many new features is the usage of a PageTheme class in themes. Previously themes didn’t have such as class. A PageTheme class is kind of what a controller is for a package.

A PageTheme class is optional for themes, which means a theme will install without it. But having a PageTheme class gives you more control over your theme. You can define custom css classes for your blocks here for example as well as load Javascript and CSS assets you need in your theme.

Documentation is still in the early stages when it comes to Concrete 5.7. Creating a PageTheme class is easy but getting it to work can be tricky if you don’t know how. I could find documentation on creating one in the application/themes folder but not for creating one in a theme contained in a package.

So here’s how to install a PageTheme class for your custom package.

Let’s say your package’s name is ‘MyAwesomePackage’ and you have a theme in this package called ‘MyAwesomeTheme’ . Your package’s handle will then be ‘my_awesome_package’ and the handle for this theme will be ‘my_awesome_theme’. In that theme you will have a class called ‘PageTheme’ and the filename will be ‘page_theme.php’.

This is wat your directory structure will look like so far :

– /packages/my_awesome_package
    – /themes/my_awesome_theme
        – /page_theme.php

Then you will need to namespace your theme; in this case the namespace will be : Concrete\Package\MyAwesomePackage\Theme\MyAwesomeTheme

In code :

Another important thing : If you add this after you installed your theme you will have to trigger detection for this class as Concrete will otherwise ignore it if it wasn’t present when the theme was installed. There are two ways to do this:

1.) Activate another theme, then reactive your theme.
2.) Alter the record in the table ‘PageThemes’ of your database and set the value of column ‘pThemeHasCustomClass’ to ‘1’ in the record belonging to your theme.

The last one is easier and safer to do I think because switching themes might break things but that’s just a guess.

That’s all folks! Happy coding!

Concrete5.7 : Javascript validation for a block’s form

If you are developing a block for Concrete 5.7 you might be looking for the Javascript function ‘ccmValidateBlockForm’ that handles the clientside validation of your block’s form. It seems to have dissappeared in Concrete 5.7 which leaves you with no way to prevent the form from being submitted if it contains validation errors.

I ran into this problem recently as I was developing my own block. The wrong approach is to listen to a form submit event. I tried this but discovered it submitted anyway as Concrete was triggering a submit with Javascript. The trick is to prevent that script from being triggered. Concrete listens to a click on the form’s submit button which is in fact not a submit button but an anchor using Javascript to trigger the click event on the real submit button which is hidden from sight.

This is how to solve it:


Replace ‘myFormValidationFunction’ with the name of your function that validates the form. Return false to prevent the form from submitting or true to allow it to submit.

Concrete 5.7 : Creating a single page for the frontend

In this post I would like to show you how to create a single page in your package for the frontend of a Concrete 5.7 website. In this tutorial we will call that package ‘YourPackage’ but of course that should be whatever your package is called.

Let’s say you want to create a single page where visitors can sign up for a newsletter. A single page is composed of a template and a controller (The controller is optional).

We will call our controller ‘SubscribeTo’. Following C5’s naming conventions this implies that :

    • The filename of the template will be called ‘subscribe_to.php’.
    • The filename of the controller will be called ‘subscribe_to.php’.

Your directory structure will look like this:

For the controller :


For the template :


And this is what your controller file will look like:

Now let’s say you want to install the single page when your package get’s installed. We will add a method to the package controller in order to do so. (The package controller is  :  /packages/your_package/controller.php).

Now the single page gets installed when you install your package. In this example I added the method ‘addSinglePage’ to the package controller but if you want to follow programming conventions it is better to create a separate class with this method (like a service/util). This way you delegate the logic. That makes it easier to refactor and you can call the method from other packages or code you create.