Create custom Controller

Create custom controller

The base of the cms is based on the controllers, it is they which allow to generate a page on your site. Before for each update, you had to save your custom code to deliver it later, now I'll show you how to create a Custom controller that will allow you to continue developing without having to reset your work.

The plugins folder

In the src/Controller folder create a new folder called "Plugins" and create inside a new controller.

Please note that the name must always contain the word Controller.

Example :

Create custom controller

Copy paste the following code


namespace App\Controller\Plugins;

use App\Settings\Api;
use App\Settings\CmsSettings;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\EventListener\AbstractSessionListener;

class CustomRankController extends AbstractController

     * @Route("/players", name="game.players.liste",  requirements={"_locale": "en|fr"})
    public function listeJoueurs(CmsSettings $settings): Response
        // your code

        return $this->render($settings->get('theme') . 'folderToTwig', [
            // Data pass to twig

I will not explain the entire operation of a controller for this follow the official doc:

The follow code it's for get your template, an controller = an template file (html.twig). U can create this file in existing template folder or create plugins folder in template and add here

return $this->render($settings->get('theme') . 'folderToTwig', [
   // Data pass to twig

Change folderToTwig to per example :

Scroll to Top