ibexa/twig-components
Ibexa DXP Twig Components provides reusable Twig components and helpers used across Ibexa DXP. Install and use it as part of a full Ibexa DXP setup rather than standalone. Licensed under Ibexa Business Use (BUL) or Trial/Test (TTL).
## Getting Started
### Minimal Setup
1. **Installation**:
```bash
composer require ibexa/twig-components
Requires Ibexa DXP (or a compatible Twig environment). For Laravel, pair with spatie/laravel-twig.
First Use Case: Render a basic table with CMS content (or Eloquent data):
{% use 'ibexa:table.html.twig' %}
{{ ibexa.table({
'data': contentList,
'columns': [
{ 'label': 'Title', 'property': 'title' },
{ 'label': 'Date', 'property': 'publish_date' }
]
}) }}
Where to Look First:
resources/views/components/table.html.twig (for template structure).config/ibexa.php (if Ibexa DXP is installed) for default settings.Data Binding:
Content objects or Location collections directly.
{{ ibexa.table({ data: locations, columns: [...] }) }}
// app/Extensions/TableDataExtension.php
public function getTableData($data) {
return array_map(fn($item) => [
'title' => $item->name,
'date' => $item->created_at->format('Y-m-d')
], $data);
}
{% set tableData = this.getTableData(posts) %}
{{ ibexa.table({ data: tableData, columns: [...] }) }}
Column Customization:
{% set columns = [] %}
{% for field in content.fields %}
{% set columns = columns|merge([{
'label': field.name,
'property': 'value.' ~ field.identifier
}]) %}
{% endfor %}
{{ ibexa.table({ data: contentList, columns: columns }) }}
{{ column.value|ibexa_table_cell_renderer }}
Pagination/Sorting:
{{ ibexa.table({
data: posts->paginate(10),
columns: [...],
pagination: true
}) }}
Styling:
// resources/scss/ibexa/_table.scss
.ibexa-table {
--table-border-color: #333;
}
{{ ibexa.table({ data: [...], class: 'table-auto border-collapse' }) }}
AppServiceProvider:
public function boot() {
$this->loadViewsFrom(__DIR__.'/../vendor/ibexa/twig-components/src/Resources/views', 'ibexa');
$this->app['twig']->addExtension(new IbexaTableExtension());
}
// app/Helpers/TwigHelper.php
public static function renderTwigComponent($view, $data) {
return \Twig\Environment::create()->render($view, $data);
}
@php echo \App\Helpers\TwigHelper::renderTwigComponent('ibexa:table.html.twig', $tableData) @endphp
$tableData = array_map(function($item) {
return [
'id' => $item['id'],
'name' => $item['attributes']['name'],
];
}, $apiResponse);
Twig Dependency:
spatie/laravel-twig or render Twig components via PHP helpers (as shown above).CMS-Specific Assumptions:
ibexa.Table expect Ibexa Content objects or Location collections. Passing raw arrays may break.public function normalizeTableData($data) {
return array_map(function($item) {
return [
'title' => $item->getField('title')->value,
'date' => $item->getField('publish_date')->value,
];
}, $data);
}
Styling Conflicts:
.ibexa-table {
--table-bg-color: theme('colors.white');
--table-header-bg: theme('colors.gray.100');
}
Pagination Quirks:
pagination option may not work out-of-the-box with Laravel’s paginator.Illuminate\Pagination\LengthAwarePaginator:
{% if data instanceof Illuminate\Pagination\LengthAwarePaginator %}
{% set pagination = {
'total': data->total(),
'perPage': data->perPage(),
'currentPage': data->currentPage(),
'lastPage': data->lastPage()
} %}
{% endif %}
Missing Bundles Exception Handling:
composer require ibexa/core-bundle
composer.json includes all necessary Ibexa dependencies and run composer install or composer update.Template Overrides:
resources/views/components/ibexa/table.html.twig to debug rendering issues.Data Validation:
dump() in Twig to inspect passed data:
{% dump(data) %}
{{ ibexa.table({ data: data, columns: columns }) }}
Extension Debugging:
$this->app['twig']->getExtension('ibexa_table')->getFunctions();
Custom Components:
app/Resources/views/components/ibexa/.Card component by copying the table structure.Twig Extensions:
// app/Extensions/CustomTableExtension.php
class CustomTableExtension extends \Twig\Extension\AbstractExtension {
public function getFunctions() {
return [
new \Twig\TwigFunction('custom_table_cell', [$this, 'renderCell']),
];
}
public function renderCell($value, $type) {
// Custom rendering logic
return "<span class='{$type}'>{$value}</span>";
}
}
{{ column.value|custom_table_cell('highlight') }}
Configuration:
config/ibexa.php (if Ibexa DXP is installed) or environment variables:
'table' => [
'default_columns' => [
['label' => 'ID', 'property' => 'id'],
],
],
JavaScript Integration:
attr filter:
<button {{ attr({'class': 'ibexa-table-sort', 'data-sort': column.property}) }}>
{{ column.label }}
</button>
document.querySelectorAll('.ibexa-table-sort').forEach
How can I help you explore Laravel packages today?