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.
https://github.com/jenstornell/snippy
Kirby Snippy
Version 0.1
With this plugin you can have a modular snippet structure to your snippets.
New way of adding snippets
snippet/menu/menu.php
snippet/menu/menu.scss
snippet/logo/logo.php
snippet/logo/logo.scss
- Bundle css/scss/less together with the snippet in a folder.
- Delete a folder and the whole module is gone.
Snippets
In Kirby you use snippets like this:
snippet('header'); //site/snippets/header.php
Snippy
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.
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.
- 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.
Requirements
Kirby 2.3
5 Likes
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.
https://github.com/jenstornell/snippy
@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. 
Yeah, but that goes to all the features.
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? 
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. 
That’s a great answer!
I don’t agree but that’s not so unusual. 
Thanks! 
github.com/jenstornell/kirby-snippy
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
snippet/logo/logo.php
snippet/logo/logo.scss
snippet/header/menu/menu.php
snippet/header/menu/menu.scss
Template - Without Snippy
snippet('logo/logo');
snippet('header/menu/menu');
Template - With Snippy
snippet('logo');
snippet('menu');