Installation
composer require chaplean/cms-bundle
Register the bundle in config/bundles.php (Symfony 4+):
return [
// ...
Chaplean\Bundle\CmsBundle\ChapleanCmsBundle::class => ['all' => true],
];
Basic Configuration
Add minimal config/packages/chaplean_cms.yaml:
chaplean_cms:
modules:
block: true
page: true
post:
category: { news: true, testimonial: false }
action: ['add', 'remove']
media: true
template:
front_layout: 'AppBundle::layout.html.twig'
front_route: 'homepage'
First Use Case Generate a basic page via CLI:
php bin/console chaplean:cms:page:create --title="Home" --slug="home"
Access the backoffice at /cms/backoffice (default route: cms_back_home).
Content Management
PageManager service to CRUD pages:
$page = $this->get('chaplean_cms.page.manager')->findOneBy(['slug' => 'home']);
$page->setContent('<h1>Welcome</h1>')->save();
PostManager:
$post = $this->get('chaplean_cms.post.manager')->create(
'news',
['title' => 'Breaking News', 'content' => '...']
);
Blocks & Media
{% for block in page.blocks %}
{{ render_block(block) }}
{% endfor %}
MediaManager:
$media = $this->get('chaplean_cms.media.manager')->upload(
$file,
'images'
);
Templates & Routing
front_layout in Twig to wrap CMS content:
{# AppBundle/Resources/views/layout.html.twig #}
{% block content %}
{{ include('ChapleanCmsBundle::page.html.twig', { page: page }) }}
{% endblock %}
# config/routes.yaml
chaplean_cms_page:
path: /{slug}
defaults: { _controller: 'ChapleanCmsBundle:Page:show' }
Backoffice Integration
back_layout:
{# AppBundle/Resources/views/backoffice.html.twig #}
{% extends 'ChapleanCmsBundle::layout-backoffice.html.twig' %}
{% block sidebar %}
{{ parent() }}
<li><a href="{{ path('app_custom_route') }}">Custom</a></li>
{% endblock %}
Deprecated Symfony Version
AppKernel) may break in Symfony 4+. Use config/bundles.php instead.Configuration Overrides
front_layout throws a RuntimeException. Always define it in config.yml.Media Paths
var/media/ by default. Ensure the directory is writable:
mkdir -p var/media && chmod -R 775 var/media
Post Categories
news: true) appear in the backoffice. Disable unused types to avoid clutter.Route Conflicts
front_route (app_front) may clash with existing routes. Rename it in config:
front_route: 'app_home'
Enable Debug Mode
Add to config/packages/dev/chaplean_cms.yaml:
debug: true
Logs errors to var/log/chaplean_cms.log.
Clear Cache After Config Changes
php bin/console cache:clear
Dump Page/Post Data
Use the debug:container command to inspect services:
php bin/console debug:container chaplean_cms.page.manager
Custom Block Types
Extend the block system by creating a new block class and registering it in the BlockManager:
// src/Service/CustomBlockManager.php
public function registerBlocks()
{
$this->manager->addBlockType(
'custom',
'AppBundle\Entity\CustomBlock',
'AppBundle:Block:custom.html.twig'
);
}
Override Twig Functions
Replace default Twig functions (e.g., render_block) in your theme:
{% macro render_block(block) %}
{# Custom logic here #}
{{ block.content|raw }}
{% endmacro %}
Event Listeners
Hook into CMS events (e.g., page.save):
// src/EventListener/CmsListener.php
public function onPageSave(PageEvent $event)
{
if ($event->getPage()->getSlug() === 'home') {
$event->setContent($event->getContent() . '<!-- Analytics -->');
}
}
Register in services.yaml:
services:
AppBundle\EventListener\CmsListener:
tags:
- { name: kernel.event_listener, event: chaplean.cms.page.save, method: onPageSave }
Custom Backoffice Routes
Add routes to config/routes.yaml:
app_cms_custom:
path: /cms/custom
controller: AppBundle\Controller\CustomCmsController::index
How can I help you explore Laravel packages today?