ebitkov/bootstrap-twig-components
Installation:
composer require ebitkov/bootstrap-twig-components).composer require symfony/ux-twig-component).config/bundles.php (if applicable).First Use Case:
{% import _self as bootstrap %}
{{ bootstrap.alert({
type: 'success',
message: 'Operation completed successfully!'
}) }}
role="alert", aria-live).Where to Look First:
Resources/views/ directory (if available) for component templates.Component Composition:
card with alert inside):
{{ bootstrap.card({
header: 'Title',
body: bootstrap.alert({ type: 'info', message: 'Details' })
}) }}
card.body as a block).Dynamic Attributes:
{{ bootstrap.button({
label: 'Click me',
attributes: { 'data-custom': 'value', 'class': 'btn-lg' }
}) }}
aria-* and role attributes for accessibility (e.g., role="button" for interactive elements).Conditional Rendering:
if to toggle components:
{% if show_notification %}
{{ bootstrap.alert({ type: 'warning', message: 'Check your input!' }) }}
{% endif %}
Laravel Integration:
TwigBridge (e.g., spatie/laravel-twig) to embed Twig components in Blade:
@twig({{ $componentOptions }})
Custom Components:
Resources/views/ (e.g., bootstrap/alert.html.twig).bootstrap.form with Laravel validation errors).Asset Management:
form_row with Bootstrap components for consistent styling:
{{ form_row(form.email, { wrapper_class: 'mb-3' }) }}
col-md-6) via the attributes option:
{{ bootstrap.card({ attributes: { class: 'col-md-4' } }) }}
{{ bootstrap.script('bootstrap.bundle.js') }}
Archived Status:
accordion).Symfony-Specific:
spatie/laravel-twig carefully.ComponentNotFoundException if the component isn’t implemented. Check the Bootstrap docs for unsupported components.Attribute Overrides:
btn btn-primary) may clash with custom attributes. Use !important sparingly or adjust CSS.Template Overrides:
resources/views/components/bootstrap/button.html.twig).{{ dump(component_options) }} to inspect passed options.JavaScript Issues:
Uncaught ReferenceError (missing JS) or TypeError (malformed markup).Caching:
php bin/console twig:cache:clear) if changes to templates aren’t reflected.Partial Components:
{% include %} for reusable snippets (e.g., a bootstrap/_partials/alert.html.twig):
{% include 'bootstrap/_partials/alert.html.twig' with {
type: 'danger',
message: error_message
} %}
Accessibility:
role and aria-* attributes are set (e.g., role="alert" for alerts). Override via options if needed:
{{ bootstrap.alert({ attributes: { 'aria-live': 'polite' } }) }}
Performance:
{{ bootstrap.script('...') }}.Testing:
TwigTest or Laravel’s Pest:
$twig->render('@bootstrap/alert', ['type' => 'success', 'message' => 'Test']);
Fallbacks:
{{ bootstrap.button({
label: label ?? 'Click',
attributes: attributes ?? {}
}) }}
How can I help you explore Laravel packages today?