Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Templatebundle Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require benmacha/templatebundle ^1.0
    

    Register the bundle in config/bundles.php:

    return [
        // ...
        Benmacha\TemplateBundle\BenmachaTemplateBundle::class => ['all' => true],
    ];
    
  2. 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
    
  3. First Use Case: Generate a CRUD for an entity (e.g., Post):

    php bin/console benmacha:generate:crud Post
    

    This creates:

    • Controller, Service, Repository, and Twig templates.
    • Auto-generates a menu entry in the admin panel.

Implementation Patterns

Workflows

  1. CRUD Generation:

    • Run benmacha:generate:crud EntityName to scaffold CRUD operations.
    • Extend the generated 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();
          }
      }
      
  2. Twig Integration:

    • Use the bundle’s Twig extensions for admin layouts:
      {% extends 'BenmachaTemplateBundle:layout.html.twig' %}
      {% block body %}
          {{ include('BenmachaTemplateBundle:Crud:list.html.twig', {'entity': post}) }}
      {% endblock %}
      
  3. Customizing Admin Panel:

    • Override the base template (BenmachaTemplateBundle:layout.html.twig) in your theme:
      {% extends 'BenmachaTemplateBundle:layout.html.twig' %}
      {% block stylesheets %}
          {{ parent() }}
          {{ encore_entry_link_tags('admin') }}
      {% endblock %}
      
  4. Entity-Specific Templates:

    • Place Twig templates in templates/BenmachaTemplateBundle/Crud/Post/ to override defaults.

Integration Tips

  • Doctrine ORM: Ensure your User entity matches the user.class and user.picture config.
  • Assets: Place logos in bundles/yourbundle/img/ and reference them in config.
  • Menu Customization: Extend the generated menu by overriding BenmachaTemplateBundle:Menu:admin.html.twig.

Gotchas and Tips

Pitfalls

  1. Outdated Package:

    • Last release in 2019; test thoroughly. May conflict with newer Symfony (5.4+) or Doctrine versions.
    • Fix: Fork the repo and update dependencies (e.g., symfony/twig-bridge, doctrine/orm).
  2. Repository Extensions:

    • Forgetting to extend BaseRepository breaks CRUD queries.
    • Fix: Use a trait or abstract class to enforce inheritance:
      abstract class CustomBaseRepository extends BaseRepository {}
      
  3. Twig Template Overrides:

    • Overriding templates in the wrong namespace (e.g., App:Crud:list.html.twig instead of BenmachaTemplateBundle:Crud:list.html.twig) may fail silently.
    • Fix: Use {% extends 'BenmachaTemplateBundle::layout.html.twig' %} explicitly.
  4. Logo Paths:

    • Hardcoded paths in config may break if assets are moved.
    • Fix: Use %kernel.project_dir% in paths:
      logo_path: '%kernel.project_dir%/public/bundles/yourbundle/img/logo.png'
      

Debugging

  • Command Errors:

    • Check bin/console benmacha:generate:crud --help for arguments.
    • Enable debug mode (APP_DEBUG=1) to see Twig/Doctrine errors.
  • Menu Not Showing:

    • Verify the menu template (BenmachaTemplateBundle:Menu:admin.html.twig) is not overridden incorrectly.
    • Clear cache:
      php bin/console cache:clear
      

Extension Points

  1. Custom CRUD Actions:

    • Add methods to the generated controller and link them in Twig:
      <a href="{{ path('app_post_archive') }}">Archive</a>
      
  2. Dynamic Config:

    • Override config via environment variables:
      # .env
      BENMACHAT_TEMPLATE_SITE_NAME=%env(string:APP_NAME)%
      
  3. Event Listeners:

    • Subscribe to kernel.request to modify CRUD behavior:
      public function onKernelRequest(GetResponseEvent $event) {
          if ($event->getRequest()->attributes->get('_route') === 'app_post_edit') {
              // Custom logic
          }
      }
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui