
I sometimes package blocks into plugins to be able to re-use them more easily. When a block includes a CSS or JS, I would like Kirby to auto include it when the css(‘@auto’) is called. This eway the CSS and JS files for the specific block I packaged into a plugin are only loaded when the block is actually in use.
I’m talking about these helpers:
Example
Plugin index-php
<?php
// Slider block plugin
Kirby::plugin('my/plugin', [
'snippets' => [
'blocks/block' => __DIR__ . '/snippets/blocks/block.php'
],
'blueprints' => [
'blocks/block' => __DIR__ . '/blueprints/blocks/block.yml'
],
'js' => [
'assets/js/block' => __DIR__ . '/assets/js/block.js'
]
]);
?>Inside template HTML header
<?php
css('@auto');
js('@auto')
?>
Was thinking that this could rather be combined/realized as auto assets for snippets (since blocks are just snippets):
Cms\App::snippet() actually tracks each requested snippetcss('@snippets') which grabs the tracked list and adds CSS/JS for each used snippet
Also related https://feedback.getkirby.com/206


We have implemented a new template stack feature, which can be used to push styles and scripts from snippets into the <head> for example. It’s not 100% the solution that is suggested here, but in our opinion it’s actually a lot more powerful and can be used to create the same result: https://github.com/getkirby/kirby/pull/7867