Installation Add the bundle via Composer:
composer require "elao/form-bundle":"~2.1"
Enable it in AppKernel.php:
new Elao\Bundle\FormBundle\ElaoFormBundle(),
Twig Configuration
Apply the global form theme in config/packages/twig.yaml:
twig:
form_themes:
- "@ElaoForm/Form/form_elao_layout.html.twig"
Alternative: Apply it per-form in Twig:
{% form_theme form '@ElaoForm/Form/form_elao_layout.html.twig' %}
First Use Case
Use the help option to add a help block to a field:
$builder->add('email', EmailType::class, ['help' => 'A valid email address']);
Render the form in Twig:
{{ form_start(form) }}
{{ form_row(form.email) }}
{{ form_end(form) }}
Dynamic Form Collections
Use data-collection for sortable/draggable collections (requires Elao/form.js):
{% for item in form.items %}
<div data-collection="{{ form.vars.collection_name }}">
{{ form_row(item) }}
</div>
{% endfor %}
Initialize with JavaScript:
$('[data-collection]').collection();
Button Shortcuts Add submit/reset buttons via form options:
$builder->setOptions([
'submit' => true, // Adds default submit button
'reset' => true, // Adds default reset button
]);
Custom Help Blocks Extend the default help template by overriding:
{% block elao_form_help %}
<div class="help-block custom-style">
{{- block('elao_form_help_content') -}}
</div>
{% endblock %}
elao/form.js is included for collection features:
{{ encore_entry_link_tags('app') }} {# or manual JS include #}
['help' => 'app.form.email_help']
in translations/messages.en.yaml.Deprecated Features
submit/reset options) may conflict with Symfony’s built-in attr or row_attr.JavaScript Dependencies
elao/form.js is required for collection features. Missing it breaks drag-and-drop/sorting.elao/form.js.Template Overrides
form_elao_layout.html.twig requires copying the entire template. Use {% extends %} carefully:
{% extends '@ElaoForm/Form/form_elao_layout.html.twig' %}
{% block elao_form_row %}...{% endblock %}
Collection Not Working? Check for:
data-collection attribute on container elements.$ is not defined).elao/form.js → your code).Help Text Not Showing? Verify:
help option set.form_theme is applied (global or per-form)..help-block class.Custom Field Types Extend the bundle’s field templates by creating a new theme:
# templates/elao_custom_theme.html.twig
{% extends '@ElaoForm/Form/form_elao_layout.html.twig' %}
{% block elao_form_row %}
<div class="custom-wrapper">
{{ parent() }}
</div>
{% endblock %}
Apply it via:
{% form_theme form '@ElaoForm/Form/form_elao_layout.html.twig', 'elao_custom_theme.html.twig' %}
Dynamic Help Blocks
Use Twig’s form_help block to customize help content:
{% block elao_form_help_content %}
{{ form_help(form) }} {# Default help #}
<small>Additional info: {{ form.vars.custom_data }}</small>
{% endblock %}
Button Styling Override button templates:
{% block elao_form_submit_button %}
<button type="submit" class="btn btn-primary">
{{ block('elao_form_submit_button_content') }}
</button>
{% endblock %}
How can I help you explore Laravel packages today?