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.
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:
In Snippy you use snippets like this:
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
- 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.
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.
- 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.
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.
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