Tailwind Merge
// site/snippets/component.php
<div <?= merge('h-full w-full bg-neutral-100', $class) ?>></div>
// site/templates/default.php
<?php snippet('component', ['class' => 'w-1/2']) ?>
// output
<div class="h-full bg-neutral-100 w-1/2"></div>
Intelligently merge Tailwind classes without style conflicts in your Kirby templates
Usage
This plugin provides two helper functions to use in your blueprints. Whether functions should be registered can be controlled in your config.php
, see Options.
attr()
This helper function works similar to the Kirby built-in attr()
function and overwrites it to support Tailwind Merge behaviour for the class
attribute.
You'll need to disable the built-in attr()
helper at the top-most location in your index.php
file - before Kirby is loaded.
define("KIRBY_HELPER_ATTR", false);
Example
// site/snippets/component.php
<div <?= attr(['class' => ['h-full w-full bg-neutral-100', $class], 'data-attr' => 'hello world!']) ?>>[...]</div>
// site/templates/default.php
<?php snippet('component', ['class' => 'w-1/2']) ?>
// output
<div class="h-full bg-neutral-100 w-1/2" data-attr="hello world!">[...]</div>
merge()
merge()
applies Tailwind Merge behaviour and outputs a class attribute.
Example
// site/snippets/component.php
<div <?= merge('h-full w-full bg-neutral-100', $class) ?>>[...]</div>
// site/templates/default.php
<?php snippet('component', ['class' => 'w-1/2']) ?>
// output
<div class="h-full bg-neutral-100 w-1/2">[...]</div>
Options
Option | Default | Description |
---|---|---|
prefix |
Set a prefix for your tailwind classes | |
helpers.attr |
true |
Register the attr() helper function |
helpers.merge |
true |
Register the merge() helper function |
Options allow you to fine tune the behaviour of the plugin. You can set them in your config.php
file:
return [
'tobimori.tailwind-merge' => [
'prefix' => 'tw-',
],
];
Related plugins
FeedReader
by Uwe Gehring
- K3
Kirby Template Sugar
by Arno Schlipf
- K3
- K4

Kirby Vite
by Arno Schlipf
- K3
- K4
Feed and Sitemap
by Bruno Meilick
- K3
- K4
Field Ecco
by Bruno Meilick
- K3
- K4
Handlebars Templates
by Bruno Meilick
- K3
- K4
HTML Purifier
by Bruno Meilick
- K3
- K4
Mobile Detect
by Bruno Meilick
- K3
- K4
Random
by Bruno Meilick
- K3
- K4
Better Search
by Bart Vandeputte
- K3
- K4

Laravel Mix Helper
by Diverently
- K3
- K4
Template Attributes
by Fabian Michael
- K3
- K4

Consent Gate
by fendinger
- K3
GEO
by Kirby Team
- K3
- K4
Choices
by hana+nils
- K3
List Methods
by hana+nils
- K3
- K4
snippetWhen Helper
by hana+nils
- K3
- K4
Tree Methods
by hana+nils
- K3
- K4
Type Methods
by hana+nils
- K3
- K4

XSLT Templates
by hana+nils
- K3
Carver
by Hash&Salt
- K3
Chopper
by Hash&Salt
- K3
- K4
Gilmour
by Hash&Salt
- K3
Highlighter
by Johann Schopplich
- K3
- K4

Blade Templates
by Lukas Leitsch
- K3
- K4
Laravel Vite
by Lukas Kleinschmidt
- K3
- K4
Snippet Controller
by Lukas Kleinschmidt
- K3
- K4
Cookie Consent Modal
by Michael Scheurich
- K3
- K4
Kirby Inherit
by Microman
- K3
- K4
Detect Adblock
by oweb studio
- K3
- K4

Plates
by oweb studio
- K3
- K4

Template Stacks
by oweb studio
- K3
- K4
Cookie Approval
by Timo Schneider
- K3
- K4
Similar
by Sonja Broda
- K3
- K4

Twig Templates
by wearejust
- K3
- K4
KirbytextWrap
by Yoan Malié
- K3

Cookieconsent
by Zephir Software Design AG
- K3
- K4
Other plugins by Tobias Möritz

BlurHash
by Tobias Möritz
- K3
- K4

Icon Field
by Tobias Möritz
- K3
- K4

ImageMagick Extended
by Tobias Möritz
- K3
- K4

ThumbHash
by Tobias Möritz
- K3
- K4