Installation
Add the bundle to your composer.json:
composer require bkstg/core-bundle
Register it in config/bundles.php:
return [
// ...
Backstage\CoreBundle\BackstageCoreBundle::class => ['all' => true],
];
Dependencies Ensure these required bundles are installed and configured:
doctrine/doctrine-bundleexercise/htmlpurifier-bundlefriendsofsymfony/ckeditor-bundleknplabs/knp-menu-bundleknplabs/knp-paginator-bundle (implied by the README’s context)Follow the standard distribution for default configurations.
First Use Case
Leverage the menu builder (knp-menu-bundle) for navigation:
{{ knp_menu('backstage_menu', {
'rootName': 'backstage',
'currentUri': app.request.getUri()
}) }}
Configure the menu in config/packages/knp_menu.yaml:
knp_menu:
backstage_menu:
items:
dashboard:
label: Dashboard
uri: /dashboard
Twig Integration
The bundle provides Twig extensions for common Backstage patterns (e.g., menus, HTML sanitization). Extend templates in templates/backstage/:
{% extends 'backstage/base.html.twig' %}
{% block body %}
{{ parent() }}
{# Custom content #}
{% endblock %}
CKEditor Configuration
Use the ckeditor_bundle for rich text editing. Configure in config/packages/fos_ckeditor.yaml:
fos_ckeditor:
base_path: /bundles/backstage/ckeditor
config:
toolbar: ['Bold', 'Italic', 'NumberedList']
Doctrine Entities
The bundle likely includes base entities (e.g., User, Page). Extend them in src/Entity/:
namespace App\Entity;
use Backstage\CoreBundle\Entity\BaseEntity;
class CustomPage extends BaseEntity { ... }
Event Listeners
Hook into Backstage events (e.g., backstage.page.publish). Register in src/EventListener/:
namespace App\EventListener;
use Backstage\CoreBundle\Event\PageEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class PagePublishListener implements EventSubscriberInterface {
public static function getSubscribedEvents() {
return [PageEvents::PAGE_PUBLISH => 'onPagePublish'];
}
public function onPagePublish(PagePublishEvent $event) { ... }
}
assets/backstage/.htmlpurifier to user-generated content:
{{ content|purify_html }}
knp_paginator for lists:
$pages = $paginator->paginate(
$pagesQuery,
$request->query->getInt('page', 1),
10
);
Dependency Conflicts
composer why-not to debug conflicts.friendsofsymfony/ckeditor-bundle fails, check for version mismatches in composer.lock.Menu Configuration
backstage_menu must match the Twig template’s expected name. Misconfiguration causes blank menus.php bin/console debug:container knp_menu.menu_manager
Doctrine Migrations
php bin/console doctrine:migrations:migrate
order).Twig Autoloading
templates/backstage/ is in your Twig loader paths. Add to config/packages/twig.yaml:
twig:
paths: ['%kernel.project_dir%/templates/backstage']
php bin/console debug:event-dispatcher
php bin/console cache:clear
rm -rf var/cache/*
Custom Templates
Override bundle templates by placing them in templates/backstage/BackstageCoreBundle/.
Service Overrides Extend services via compiler passes or configuration:
# config/packages/backstage.yaml
backstage_core:
services:
app.custom_service: '@app.service.id'
HTML Purifier Rules
Customize allowed tags in config/packages/htmlpurifier.yaml:
htmlpurifier:
config:
HTML.Allowed: 'p[style],a[href],strong'
Menu Builders Create dynamic menus with a custom builder:
namespace App\Menu;
use Knp\Menu\FactoryInterface;
use Symfony\Component\HttpFoundation\Request;
class CustomMenuBuilder {
public function mainMenu(FactoryInterface $factory, array $options) {
$menu = $factory->createItem('root');
// ...
return $menu;
}
}
Register in config/packages/knp_menu.yaml:
knp_menu:
backstage_menu:
builder: app.custom_menu_builder
How can I help you explore Laravel packages today?