Configuration
Constructor options for eSheep\Twigs\Extension — inject a configured TailwindMerge instance and set the default options of the merge_attributes filter.
The extension works without configuration. Its constructor takes two optional named arguments.
use eSheep\Twigs\Extension;
use TalesFromADev\TailwindMerge\TailwindMerge;
$twig->addExtension(new Extension(
tailwindMerge: new TailwindMerge(),
mergeOptions: [
'remove_duplicate_classes' => true,
'tailwind_merge' => true,
],
));
tailwindMerge
An instance of TalesFromADev\TailwindMerge\TailwindMergeInterface, used by |tailwind_merge and by |merge_attributes.
Without one, the extension creates a TailwindMerge with the default configuration the first time it needs to merge classes. Pass your own to use a custom Tailwind configuration or a PSR-16 cache:
use TalesFromADev\TailwindMerge\TailwindMerge;
$twig->addExtension(new Extension(
tailwindMerge: new TailwindMerge(
additionalConfiguration: [/* see the tailwind-merge-php docs */],
cache: $psr16Cache,
),
));
The options additionalConfiguration accepts are covered in the tailwind-merge-php documentation.
mergeOptions
Defaults for |merge_attributes. A call can still override them through the filter’s third argument.
| Key | Type | Default | Effect |
|---|---|---|---|
remove_duplicate_classes |
bool |
true |
Removes repeated class names after merging. |
tailwind_merge |
bool |
true |
Resolves conflicting Tailwind classes after merging, so later classes win. |
If your project doesn’t use Tailwind CSS, turn off tailwind_merge. Otherwise classes that happen to look like Tailwind utilities can be dropped:
$twig->addExtension(new Extension(
mergeOptions: ['tailwind_merge' => false],
));