Installation
composer require dywee/core-bundle
Register the bundle in config/bundles.php:
return [
// ...
Dywee\CoreBundle\DyweeCoreBundle::class => ['all' => true],
];
First Use Case: Admin Template
Extend the base admin.html.twig template in your bundle’s Resources/views/:
{# src/YourBundle/Resources/views/admin.html.twig #}
{% extends "DyweeCoreBundle:Templates:admin.html.twig" %}
{% block metaTitle %}{{ parent() }} - Custom Title{% endblock %}
{% block body %}
<h1>Welcome to Your Admin Panel</h1>
{% endblock %}
Key Files to Explore
DyweeCoreBundle/Resources/views/Templates/admin.html.twig (base template).Event/SidebarBuilderEvent.php, DashboardBuilderEvent.php, AdminNavbarBuilderEvent.php (event classes).metaTitle, body, sidebar, etc.) in your child template.{% block sidebar %}
{{ parent() }} {# Renders parent sidebar #}
<li><a href="{{ path('your_route') }}">Custom Link</a></li>
{% endblock %}
namespace App\EventListener;
use Dywee\CoreBundle\Event\SidebarBuilderEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AdminSidebarSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
SidebarBuilderEvent::class => 'onSidebarBuild',
];
}
public function onSidebarBuild(SidebarBuilderEvent $event)
{
$sidebar = $event->getSidebar();
$sidebar->addItem('dashboard', 'Dashboard', 'fa fa-dashboard');
$event->setSidebar($sidebar);
}
}
services.yaml:
services:
App\EventListener\AdminSidebarSubscriber:
tags: ['kernel.event_subscriber']
Dywee\CoreBundle\Controller\ParentController for CRUD actions.namespace App\Controller;
use Dywee\CoreBundle\Controller\ParentController;
class PostController extends ParentController
{
public function indexAction()
{
return $this->render('App:Post:index.html.twig');
}
}
{{ form_start(form) }}
{{ form_widget(form) }}
<button type="button" class="add-item">Add Item</button>
{{ form_end(form) }}
<script>
// Bundle provides JS for dynamic collection handling
$('.add-item').click(function() {
// Leverages Dywee's JS collection logic
DyweeFormCollection.addItem('{{ form.vars.id }}');
});
</script>
Event Dispatcher Typos
EventDispatcher (note the British spelling in the README: EventDispatc).Symfony\Component\EventDispatcher\EventDispatcherInterface.Template Block Overrides
{{ parent() }} in blocks can break inheritance.parent() if extending functionality.JS Collection Dependencies
dywee-core-bundle JS assets are enqueued in your base template:
{{ parent() }} {# In your admin.html.twig #}
{{ dywee_core_js() }} {# Hypothetical helper; check bundle docs #}
Event Debugging
public function onSidebarBuild(SidebarBuilderEvent $event)
{
dump($event->getSidebar()->getItems());
}
Template Hierarchy
{% debug %} to trace template inheritance:
{% debug %}
Admin LTE Customization
admin_lte.html.twig (if provided) for deeper theming:
{% extends "DyweeCoreBundle:Templates:admin_lte.html.twig" %}
{% block stylesheets %}
{{ parent() }}
<link rel="stylesheet" href="{{ asset('css/custom.css') }}">
{% endblock %}
Custom Events
DyweeCoreEvent.Controller Traits
ParentController logic via traits:
use Dywee\CoreBundle\Controller\Traits\CrudTrait;
Asset Management
web/bundles/dyweecore/ (Symfony’s asset override convention).Data Preload for Modals
// src/Controller/ModalController.php
class ModalController extends ParentController
{
public function preloadDataAction($id)
{
$data = $this->getDataForModal($id);
return $this->json($data);
}
}
<a href="#" class="remote-modal" data-url="{{ path('modal_preload', {'id': item.id}) }}">
Open Modal
</a>
How can I help you explore Laravel packages today?