benmacha/templatebundle
Symfony bundle that generates nicely designed templates and CRUD scaffolding for your app, including auto-generated menus. Install via Composer, register the bundle, configure site name/logo/user settings, and extend BaseRepository for entities.
Installation:
composer require benmacha/templatebundle ^1.0
Register the bundle in config/bundles.php:
return [
// ...
Benmacha\TemplateBundle\BenmachaTemplateBundle::class => ['all' => true],
];
Configuration:
Add to config/packages/benmacha_template.yaml:
benmacha_template:
site_name: "YourAppName" # Required
logo_path: "bundles/yourbundle/img/logo.png" # Required
logo_path_mobile: "bundles/yourbundle/img/logo-mob.png" # Required
user:
class: App\Entity\User
picture: profile_image
First Use Case:
Generate a CRUD for an entity (e.g., Post):
php bin/console benmacha:generate:crud Post
This creates:
CRUD Generation:
benmacha:generate:crud EntityName to scaffold CRUD operations.BaseRepository to add custom queries:
class PostRepository extends BaseRepository {
public function findPublished() {
return $this->createQueryBuilder('p')
->where('p.published = :published')
->setParameter('published', true)
->getQuery()
->getResult();
}
}
Twig Integration:
{% extends 'BenmachaTemplateBundle:layout.html.twig' %}
{% block body %}
{{ include('BenmachaTemplateBundle:Crud:list.html.twig', {'entity': post}) }}
{% endblock %}
Customizing Admin Panel:
BenmachaTemplateBundle:layout.html.twig) in your theme:
{% extends 'BenmachaTemplateBundle:layout.html.twig' %}
{% block stylesheets %}
{{ parent() }}
{{ encore_entry_link_tags('admin') }}
{% endblock %}
Entity-Specific Templates:
templates/BenmachaTemplateBundle/Crud/Post/ to override defaults.User entity matches the user.class and user.picture config.bundles/yourbundle/img/ and reference them in config.BenmachaTemplateBundle:Menu:admin.html.twig.Outdated Package:
symfony/twig-bridge, doctrine/orm).Repository Extensions:
BaseRepository breaks CRUD queries.abstract class CustomBaseRepository extends BaseRepository {}
Twig Template Overrides:
App:Crud:list.html.twig instead of BenmachaTemplateBundle:Crud:list.html.twig) may fail silently.{% extends 'BenmachaTemplateBundle::layout.html.twig' %} explicitly.Logo Paths:
%kernel.project_dir% in paths:
logo_path: '%kernel.project_dir%/public/bundles/yourbundle/img/logo.png'
Command Errors:
bin/console benmacha:generate:crud --help for arguments.APP_DEBUG=1) to see Twig/Doctrine errors.Menu Not Showing:
BenmachaTemplateBundle:Menu:admin.html.twig) is not overridden incorrectly.php bin/console cache:clear
Custom CRUD Actions:
<a href="{{ path('app_post_archive') }}">Archive</a>
Dynamic Config:
# .env
BENMACHAT_TEMPLATE_SITE_NAME=%env(string:APP_NAME)%
Event Listeners:
kernel.request to modify CRUD behavior:
public function onKernelRequest(GetResponseEvent $event) {
if ($event->getRequest()->attributes->get('_route') === 'app_post_edit') {
// Custom logic
}
}
How can I help you explore Laravel packages today?