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 :

/packages/your_package/controllers/single_pages/subscribe_to.php

For the template :

/packages/your_package/single_pages/subscribe_to.php

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.

 

Published by

Justin

Justin

Hi there! I'm a software engineer currently employed at a company in The Hague in the Netherlands. You can find out more about me and my qualifications on LinkedIn (http://nl.linkedin.com/pub/justin-van-schaick/26/1b0/210). I started this blog in order to share interesting code snippets and tutorials on mainly Javascript, PHP and related frameworks. The internet is an invaluable resource for programmers and unfortunately there's never enough documentation out there. So this is me trying to contribute to that.

Leave a Reply