Skip to content

Plugin assets: integrate improvements from Kirby 4 release notes #2500

@danburzo

Description

@danburzo

The Kirby 4 release notes include a section dedicated to plugin assets:

Better plugin asset handling

  • New assets plugin extension that allows plugins to specify assets from custom paths and with a wider range of extensions than previously supported
  • New Kirby\Cms\Plugin::assets() and Kirby\Cms\Plugin::asset($assetName) methods
  • New Kirby\Cms\PluginAsset object with many methods, e.g. $plugin->asset('styles.css')->url()
  • Plugin asset media url contains a modification timestamp to easily cachebust (e.g. /media/plugins/getkirby/test-plugin/2375797551-472389240/styles.css)
  • css() and js() helpers support passing plugin and plugin assets objects to include all assets of the plugin:
css([
  'assets/css/index.css',
  $kirby->plugin('foo/bar')
]);

css([
  'assets/css/index.css',
  $kirby->plugin('foo/bar')->assets(),
]);

css([
  'assets/css/index.css',
  $kirby->plugin('foo/bar')->asset('styles.css'),
]);

The Custom plugins page includes a short section on plugin assets, but does not include details on how to access them in templates.

I missed the release notes so I went on a tangent trying to figure out content hashing for plugin assets, so more visibility to the fact that these can already be hashed with core functionality would be welcome. Is it treated in another section of the docs?

If not, I would make a PR to add this info to the Custom plugins page, if that’s the best place for it.

Note that as of Kirby 5.1.3, some of these helpers are broken, but trivial to fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions