basic-builder/easybuilder-bundle
Installation Add the package via Composer:
composer require basic-builder/easybuilder-bundle
Enable the bundle in config/bundles.php:
return [
// ...
BasicBuilder\EasyBuilderBundle\EasyBuilderBundle::class => ['all' => true],
];
First Use Case Generate a basic page template:
php bin/console easybuilder:generate:page --name="HomePage" --template="default"
This creates a new page under templates/easybuilder/pages/HomePage.html.twig.
Key Directories
templates/easybuilder/ – Default location for generated templates.config/easybuilder/ – Configuration files for builders.src/EasyBuilder/ – Custom builder logic (if extending).Define a Template
Create a base template in templates/easybuilder/base.html.twig:
<!DOCTYPE html>
<html>
<head>
<title>{% block title %}{% endblock %}</title>
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>
Generate a Page Extend the base template:
php bin/console easybuilder:generate:page \
--name="About" \
--extends="base" \
--content="<h1>About Us</h1><p>Welcome to our site.</p>"
Render Dynamically Use Twig in a controller:
use BasicBuilder\EasyBuilderBundle\Twig\EasyBuilderExtension;
public function showPage(EasyBuilderExtension $builderExtension)
{
$content = $builderExtension->render('About');
return new Response($content);
}
Add Form Support
Configure form types in config/easybuilder/forms.yaml:
forms:
contact:
type: Symfony\Component\Form\Extension\Core\Type\FormType
fields:
- { name: "name", type: "text" }
- { name: "email", type: "email" }
Generate a Form Page
php bin/console easybuilder:generate:page \
--name="ContactForm" \
--template="form" \
--form="contact"
Render in Twig
{{ easybuilder_form('contact') }}
Extend Twig for reusable components:
// src/Twig/EasyBuilderCustomExtension.php
namespace App\Twig;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
class EasyBuilderCustomExtension extends AbstractExtension
{
public function getFunctions()
{
return [
new TwigFunction('custom_component', [$this, 'renderComponent']),
];
}
public function renderComponent(string $name, array $data = [])
{
// Logic to render dynamic components
}
}
Register in config/packages/twig.yaml:
twig:
extensions:
- App\Twig\EasyBuilderCustomExtension
Template Caching Clear the Twig cache after generating new templates:
php bin/console cache:clear
Namespace Conflicts
Ensure custom builder classes are namespaced properly (e.g., App\EasyBuilder\CustomBuilder) to avoid collisions with the bundle’s default classes.
Form Validation Errors
If forms fail silently, check config/easybuilder/forms.yaml for missing constraints or incorrect field types. Validate with:
php bin/console debug:form your_form_type
Overwriting Default Templates
Avoid naming custom templates the same as built-in ones (e.g., base.html.twig). Prefix with your bundle name (e.g., app_base.html.twig).
Check Generated Files
Verify templates are created in templates/easybuilder/ after generation commands fail.
Enable Twig Debugging
Set debug: true in config/packages/twig.yaml to see template errors in detail.
Log Builder Events
Enable logging in config/easybuilder.yaml:
logging: true
Custom Builders Extend the base builder class:
// src/EasyBuilder/CustomBuilder.php
namespace App\EasyBuilder;
use BasicBuilder\EasyBuilderBundle\Builder\AbstractBuilder;
class CustomBuilder extends AbstractBuilder
{
protected function configure()
{
$this->addOption('custom_option', null, 'Custom option value');
}
}
Register in config/easybuilder.yaml:
builders:
custom:
class: App\EasyBuilder\CustomBuilder
Hooks for Pre/Post Generation
Use Symfony events (e.g., easybuilder.page.generate) to modify generation logic:
// src/EventListener/EasyBuilderListener.php
namespace App\EventListener;
use BasicBuilder\EasyBuilderBundle\Event\PageGenerateEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class EasyBuilderListener implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
PageGenerateEvent::NAME => 'onPageGenerate',
];
}
public function onPageGenerate(PageGenerateEvent $event)
{
$event->setContent($event->getContent() . '<!-- Custom footer -->');
}
}
Asset Management Use Symfony’s asset system for generated pages:
{% block stylesheets %}
{{ parent() }}
{{ encore_entry_link_tags('app') }}
{% endblock %}
YAML vs. PHP Config
Prefer config/easybuilder.yaml for simplicity, but use config/easybuilder.php for complex logic (e.g., dynamic builder options).
Template Inheritance
Ensure {% extends %} in generated templates matches existing base templates. Use absolute paths if needed:
{% extends 'easybuilder/base.html.twig' %}
Command Arguments
Use --dry-run to preview changes without generating files:
php bin/console easybuilder:generate:page --name="Test" --dry-run
How can I help you explore Laravel packages today?