Kirby Snippy - Modular snippets

Maybe you expected me to release my Reveal plugin, but it has some issues that I need to think about first. In the meantime I release my Kirby Snippy.

Kirby Snippy

Version 0.1

With this plugin you can have a modular snippet structure to your snippets.

New way of adding snippets

  • Bundle css/scss/less together with the snippet in a folder.
  • Delete a folder and the whole module is gone.


In Kirby you use snippets like this:

snippet('header'); //site/snippets/header.php


In Snippy you use snippets like this:

snippet('header'); //site/snippets/header/header.php

Because it has a fallback you can still use your current snippet folder structure as well.

Gulp or Grunt

To have full benefit of modules you need Gulp or Grunt to compile the css and js to the assets folder.

I have no examples of this at the current time. See the Patterns plugin for inspiration.

Differences to Kirby Patterns

Benefits of Snippy

  • You don’t need to use both snippets and patterns, only snippets.
  • You don’t need to name the files header.html.php, only header.php.
  • The plugin is tiny.

Benefits of Kirby Patterns

  • Has a UI.
  • Much more advanced.

I would say, if you love snippets but want them modular, try Snippy. If you need a UI or more advanced features, use Patterns.


Kirby 2.3


Great idea as it’s indeed very tiny for what it does.

A quick note: Instead of your filename method, you can also use PHP’s basename() function. That’s probably more robust.

1 Like

Version 0.2

  • Changed filename method to basename.
  • Using spaces instead of tabs.
  • Removed use c as it was not needed.

@lukasbestle What do you think about adding a feature like this to the core? Then it would follow the same kind of rules that plugins use, folder name matches a filename with fallback to the current snippet way.

The pitfall would be that it could break sites, but then the site need to have a quite odd structure, something like this:

header/header.php // This will run first
header.php // This will run next

The old fashion user exepect header.php to run in this case.

I honestly think that this should stay a plugin. The more features there are in the core, the more difficult it gets to keep it all tidy and robust. :slight_smile:

Yeah, but that goes to all the features. :slight_smile: I don’t think we want to have a permanent feature freeze of all future features, right? What I think you are trying to say is that you don’t like my suggestion enough to merge it into the core, right? :slight_smile:

No, there will definitely be features in the future, just like with Kirby 2.3.
However I think that using snippets in subfolders can be a bit confusing for users who are just starting with Kirby. You can already use them with snippet('header/header') and the more magic we have in the core, the more complex it all gets. :wink:

That’s a great answer! :slight_smile: I don’t agree but that’s not so unusual. :wink:

Thanks! :slight_smile:

I’ve made a complete rewrite of Snippy today.

Before it was made with an extended component. The reason for the change is that a component only can be used ones.

I found another way without using a component, I registered the snippets.

Snippets in a modular approach

Your file structure


Template - Without Snippy


Template - With Snippy