Voyager 2
2.x
2.x
  • Introduction
  • Javascript
  • Media Manager
  • Plugins
  • Settings
  • bread
    • Actions
    • BREAD Builder
    • Layouts
    • Lists
    • Manipulate data
    • Multilanguage
    • Relationships
    • Validation
    • Views
  • contributing
    • Assets
    • CSS
    • Introduction
  • de
    • index
  • formfields
    • Checkboxes
    • Date & Time
    • Dynamic input
    • Formfields
    • Media Picker
    • Number
    • Password
    • Radios
    • Relationship
    • Repeater
    • Select
    • Simple array
    • Slider
    • Slug
    • Tags
    • Text
    • Toggle
  • getting-started
    • Installation
    • Prerequisites
    • Tips and tricks
    • What is Voyager
  • overriding
    • Overriding formfields
    • Icons
  • plugins
    • Assets
    • Components
    • Features
    • Filter
    • Plugin development
    • Language
    • Menu Items
    • Custom pages
    • Preferences
    • Routes
    • Settings
    • Widgets
Powered by GitBook
On this page
  • Javascript
  • CSS
  • Example

Was this helpful?

  1. plugins

Assets

PreviouspluginsNextComponents

Last updated 3 years ago

Was this helpful?

Chances are very high that you want your plugin to be able to provide Javascript and/or CSS. This can be done by implementing a contract and providing a method returning your assets as plain text. Directly providing your assets allows you to simply develop your plugin and releasing it - without the need to re-publish files with any change. Don't worry - Voyager takes care of caching your assets.

Javascript

Implement the contract Voyager\Admin\Contracts\Features\Features\Provider\JS and provide a method provideJS() returning a string containing your Javascript code.

::: info A formfield plugin automatically implements the JS contract. You don't need to do this manually! :::

Read more about public Javascript APIs

CSS

Implement the contract Voyager\Admin\Contracts\Features\Features\Provider\CSS and provide a method provideCSS() returning a string containing your CSS.

Example

use Voyager\Admin\Contracts\Plugins\GenericPlugin;
use Voyager\Admin\Contracts\Plugins\Features\Provider\{CSS, JS};

class VoyagerDocs implements GenericPlugin, CSS, JS
{
    // ...

    public function provideCSS(): string
    {
        return file_get_contents('path/to/your/asset.css');
    }

    public function provideJS(): string
    {
        return file_get_contents('path/to/your/asset.js');
    }
}
here