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 snippetAlso related https://feedback.getkirby.com/206