PHPackages                             lukaskleinschmidt/kirby-snippet-controller - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. lukaskleinschmidt/kirby-snippet-controller

ActiveKirby-plugin[Utility &amp; Helpers](/categories/utility)

lukaskleinschmidt/kirby-snippet-controller
==========================================

Kirby Snippet Controller

2.2.0(2y ago)192.1k↓50%[1 issues](https://github.com/lukaskleinschmidt/kirby-snippet-controller/issues)MITPHPPHP ^8.1

Since Dec 15Pushed 2y ago2 watchersCompare

[ Source](https://github.com/lukaskleinschmidt/kirby-snippet-controller)[ Packagist](https://packagist.org/packages/lukaskleinschmidt/kirby-snippet-controller)[ RSS](/packages/lukaskleinschmidt-kirby-snippet-controller/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (1)Versions (6)Used By (0)

Kirby Snippet Controller
========================

[](#kirby-snippet-controller)

Define snippet controllers in a similar way to how page controllers work.

How to use it
-------------

[](#how-to-use-it)

By default the plugin will try to find controllers in your `snippets` directory. Lets have a look at a example `header` snippet.

```
📁 snippets
├─ 📄 header.controller.php
└─ 📄 header.php
```

```
// header.controller.php

// The return value can be a callback
return function ($site) {
    return [
        'title' => $site->title(),
    ];
};

// Or you can simply return an array.
return [
    'title' => site()->title(),
];
```

You can also define snippet controllers in a plugin.

```
Kirby::plugin('superwoman/superplugin', [
    'snippets' => [

        // Refer to a file
        'header.controller' => __DIR__ . '/snippets/header.controller.php',

        // Return an array
        'header.controller' => [
            'title' => site()->title(),
        ],

        // Return a callback
        'header.controller' => function ($site) {
            return [
                'title' => $site->title(),
            ];
        },

    ],
]);
```

### Available callback arguments in your controllers

[](#available-callback-arguments-in-your-controllers)

You have access to all variables that are also accessible in the snippet. If you pass additional data to the snippet, you can access it in the controller as well.

> **Note**Since version [`2.0.0`](https://github.com/lukaskleinschmidt/kirby-snippet-controller/releases/tag/2.0.0) and Kirby [`3.9.6`](https://github.com/getkirby/kirby/releases/tag/3.9.6) you can also use variadic arguments.

```
snippet('header', data: ['title' => 'My Title'])

// header.controller.php

return function (string $title = 'Default Title', ...$args) {
    return [
        'title' => $title,
    ];
};
```

> **Note**Since version [`2.1.0`](https://github.com/lukaskleinschmidt/kirby-snippet-controller/releases/tag/2.1.0) you can override variables when using a controller callback.

```
snippet('header', data: ['size' => $page->size()])

// header.controller.php

return function (Field|string $size = null) {

    if ($size instanceof Field) {
        $size = $size->value();
    }

    $size = match ($size) {
        'small'  => 'height: 50vh',
        'medium' => 'height: 80vh',
        default  => 'height: 100vh',
    };

    return [
        'size' => $size,
    ];
};
```

> **Note**Since version [`2.2.0`](https://github.com/lukaskleinschmidt/kirby-snippet-controller/releases/tag/2.2.0) you can prevent a snippet from rendering in a controller callback.

```
snippet('header', data: ['size' => $page->size()])

// header.controller.php

return function (Field|string $size = null) {
    if (is_null($size)) {
        snippet_prevent();
    }

    return [
        'size' => $size,
    ];
};
```

### Naming convention

[](#naming-convention)

By default, the plugin searches for controllers by appending `.controller` to the snippet name. You can change the name resolver in the options. Changing the name also affects plugin-defined controllers.

```
// config.php

return [
    'lukaskleinschmidt.snippet-controller' => [

        // The default resolver
        'name' => fn (string $name) => $name . '.controller',

        // You might want to store controllers in a separate folder
        'name' => fn (string $name) => 'controllers/' . $name,

    ],
];
```

Commercial Usage
----------------

[](#commercial-usage)

This plugin is free. Please consider to [make a donation](https://www.paypal.me/lukaskleinschmidt/5EUR) if you use it in a commercial project.

Installation
------------

[](#installation)

### Download

[](#download)

Download and copy this repository to `/site/plugins/snippet-controller`.

### Git submodule

[](#git-submodule)

```
git submodule add https://github.com/lukaskleinschmidt/kirby-snippet-controller.git site/plugins/snippet-controller

```

### Composer

[](#composer)

```
composer require lukaskleinschmidt/kirby-snippet-controller

```

License
-------

[](#license)

MIT

Credits
-------

[](#credits)

- [Lukas Kleinschmidt](https://github.com/lukaskleinschmidt)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~81 days

Total

5

Last Release

918d ago

Major Versions

1.0.0 → 2.0.02023-08-04

### Community

Maintainers

![](https://www.gravatar.com/avatar/cfdb3936515e09409cd41df4504420d277787d8f2e212e2c7a1645995080be60?d=identicon)[lukaskleinschmidt](/maintainers/lukaskleinschmidt)

---

Top Contributors

[![lukaskleinschmidt](https://avatars.githubusercontent.com/u/10027897?v=4)](https://github.com/lukaskleinschmidt "lukaskleinschmidt (9 commits)")

### Embed Badge

![Health badge](/badges/lukaskleinschmidt-kirby-snippet-controller/health.svg)

```
[![Health](https://phpackages.com/badges/lukaskleinschmidt-kirby-snippet-controller/health.svg)](https://phpackages.com/packages/lukaskleinschmidt-kirby-snippet-controller)
```

###  Alternatives

[distantnative/retour-for-kirby

Manage redirects and track 404s right from the Kirby CMS Panel

14689.4k1](/packages/distantnative-retour-for-kirby)[mzur/kirby-uniform

A versatile Kirby plugin to handle web form actions.

26068.3k13](/packages/mzur-kirby-uniform)[arnoson/kirby-vite

Vite helper for Kirby CMS

9759.2k3](/packages/arnoson-kirby-vite)[thathoff/kirby-git-content

Plugin to track changes to content in a git repository.

15343.7k](/packages/thathoff-kirby-git-content)[sylvainjule/locator

A map &amp; geolocation field, built on top of open-source services / Mapbox

11237.3k1](/packages/sylvainjule-locator)[tobimori/kirby-seo

The default choice for SEO on Kirby: Implement technical SEO &amp; Meta best practices with ease and provide an easy-to-use editor experience

10039.7k1](/packages/tobimori-kirby-seo)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
