jmf / twig-tabs-bundle
Symfony bundle for rendering Bootstrap tabs in Twig templates.
Package info
github.com/jmfeurprier/twig-tabs-bundle
Type:symfony-bundle
pkg:composer/jmf/twig-tabs-bundle
Requires
- php: >=8.3
- jmf/template-rendering: ^2.0
- jmf/twig-tabs: ^1.0
- symfony/framework-bundle: ^7.0|^8.0
Requires (Dev)
- overtrue/phplint: ^9
- phpstan/phpstan: ^2
- phpstan/phpstan-strict-rules: ^2
- phpunit/phpunit: ^12|^13
- rector/rector: ^2
- squizlabs/php_codesniffer: ^4
- symfony/twig-bundle: ^7.0|^8.0
README
Symfony bundle integrating jmf/twig-tabs: a Twig
tabs() / tab() API that renders tabbed content in Twig templates (defaulting to Bootstrap 5 theme).
Requirements
- PHP 8.3+
- Symfony 7.0 or 8.0
Installation
Install with Composer:
composer require jmf/twig-tabs-bundle
If you have Symfony Flex, the tabs() / tab()
functions are instantly available without further configuration. Otherwise, register the bundle in
config/bundles.php:
<?php return [ // ... Jmf\TwigTabsBundle\JmfTwigTabsBundle::class => ['all' => true], ];
Quick Start
Use the tabs() and tab() functions in any Twig template:
{{ tabs(
tab('articles').label('First tab').content('<p>Content 1</p>'),
tab('authors').label('Second tab').include('path/to/template.html.twig', {foo: bar}),
tab('comments').label('With badge').content('<p>Content 3</p>').badge('5'),
) }}
Or pass an array of builders:
{{ tabs(myTabBuilders) }}
tab() builder methods
| Method | Description |
|---|---|
.label(string $label) |
Tab header label |
.content(string $html) |
Raw HTML content for the tab pane |
.include(string $path, array $parameters) |
Render a template as the tab pane content |
.badge(?string $badge) |
Optional badge displayed next to the label |
Configuration Reference
All settings are optional. Create config/packages/jmf_twig_tabs.yaml to override the defaults:
jmf_twig_tabs: # Optional prefix before the "tabs" and "tab" function names. Default: '' # Example: 'jmf_' registers 'jmf_tabs' / 'jmf_tab' instead of 'tabs' / 'tab'. prefix: '' # Twig template used as the rendering entry point. Default: '@JmfTwigTabs/bootstrap/tabs.html.twig' template_path: '@JmfTwigTabs/bootstrap/tabs.html.twig'
A sample configuration file is available in the samples/ directory.
Customising templates
The @JmfTwigTabs namespace is registered automatically and points at the Bootstrap templates
shipped by jmf/twig-tabs. To customise the markup, either set template_path to your own entry
point, or override the namespaced templates (tabs.html.twig, nav-tabs.html.twig,
nav-item.html.twig, tab-content.html.twig, tab-pane.html.twig) from your application.
License
MIT