Skip to content

Instantly share code, notes, and snippets.

@cbuchler
Created December 17, 2025 11:05
Show Gist options
  • Select an option

  • Save cbuchler/e37fcb2118f19bcd5e5b191b690bde3d to your computer and use it in GitHub Desktop.

Select an option

Save cbuchler/e37fcb2118f19bcd5e5b191b690bde3d to your computer and use it in GitHub Desktop.
This Kirby Plugin allows to convert the col spans of Kirby to Tailwind Compatible classes.
<?php
Kirby::plugin('cb/layout-tailwind', []);
if (!function_exists('kirbySpanToCols')) {
function kirbySpanToCols(string $span, int $gridCols = 12): int
{
if (strpos($span, '/') === false) {
return $gridCols;
}
[$num, $den] = array_map('intval', explode('/', $span, 2));
if ($num <= 0 || $den <= 0) {
return $gridCols;
}
$cols = (int) round($gridCols * ($num / $den));
return max(1, min($gridCols, $cols));
}
}
if (!function_exists('kirbyColumnClass')) {
function kirbyColumnClass(string $span, int $gridCols = 12, string $bp = 'md'): string
{
$cols = kirbySpanToCols($span, $gridCols);
return "col-span-12 {$bp}:col-span-{$cols}";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment