coaladmin/four-tiles-with-text-bundle
Installation Add the bundle via Composer:
composer require coaladmin/four-tiles-with-text-bundle
Enable the bundle in config/bundles.php:
return [
// ...
CoalAdmin\FourTilesWithTextBundle\CoalAdminFourTilesWithTextBundle::class => ['all' => true],
];
Basic Usage After installation, the bundle provides a reusable FourTilesWithText component for Symfony UX Live Components. Register it in your controller:
use CoalAdmin\FourTilesWithTextBundle\Component\FourTilesWithText;
#[Route('/dashboard', name: 'dashboard')]
public function dashboard(FourTilesWithText $fourTilesWithText): Response
{
return $this->render('dashboard.html.twig', [
'tiles' => $fourTilesWithText->render([
[
'title' => 'Tile 1',
'text' => 'Description for Tile 1',
'icon' => 'fas fa-chart-bar',
'color' => 'primary',
'link' => '#',
],
// Repeat for 3 more tiles
]),
]);
}
First Use Case Use the component in a dashboard to display key metrics (e.g., users, orders, revenue) with icons, colors, and links. Example Twig:
<div class="container">
{{ tiles|raw }}
</div>
Dynamic Data Binding Fetch data from a repository/service and pass it to the component:
$tiles = [
[
'title' => 'Total Users',
'text' => $userService->getTotalUsers(),
'icon' => 'fas fa-users',
'color' => 'info',
'link' => route('users.index'),
],
// ...
];
Reusable Components
Create a base template (dashboard.html.twig) to wrap the component:
{% extends 'base.html.twig' %}
{% block body %}
<div class="row">
{{ tiles|raw }}
</div>
{% endblock %}
Integration with Symfony UX Use with Turbo or Stimulus for real-time updates:
// stimulus_controller.js
import { Controller } from '@hotwired/stimulus';
export default class extends Controller {
connect() {
this.element.addEventListener('click', () => {
// Fetch updated data via API and re-render tiles
});
}
}
primary, secondary, success, etc.) across the app.col-md-3) to ensure tiles stack on mobile.'text' => $this->get('translator')->trans('dashboard.users'),
Live Component Requirements Ensure Symfony UX Live Components are installed:
composer require symfony/ux-live-component
Add to config/packages/framework.php:
'live_components' => ['*'],
Twig Security
The |raw filter is required for HTML rendering. Avoid passing untrusted data to text or title to prevent XSS.
Icon Dependencies The bundle expects Font Awesome icons by default. If using a different icon library (e.g., Bootstrap Icons), override the Twig template or CSS classes.
tiles array has exactly 4 items. The component expects 4 tiles.{{ stimulus_controller('dashboard', {}) }}
is included in the template.Custom Templates
Override the default Twig template (FourTilesWithText.html.twig) by copying it to:
templates/components/four_tiles_with_text.html.twig
Additional Fields Extend the tile structure by modifying the component class:
// src/Component/CustomFourTiles.php
public function render(array $tiles): string {
// Add custom logic (e.g., 'badge' field)
}
Dynamic Colors Use a service to generate dynamic colors based on data:
'color' => $colorService->getColorForMetric($tile['metric']),
How can I help you explore Laravel packages today?