Asset Manager

The asset manager holds containers for you JS and CSS assets.

The easiest way to use the Asset Manager is to access to it through the container$container->get('asset_manager').

Other wise just add the following parameter to the construct method of your Controller Tomahawk\Asset\AssetManagerInterface and it will get injected in through the Service Container.

Asset Containers

Asset containers are great for grouping assets under a particular group or section, e.g header and footer JS.

Adding assets

The addJs and addCss methods accepts 4 parameters:

  • name - Name of the asset
  • path - path to asset
  • dependencies - array of assets to be loaded before this
  • attributes - array of html attributes to put on tags during render

You can create a new Asset Container by doing the following:

And this is how you set dependencies:

You can also add extra parameters

Once your done you just add the container to the manager:

Outputting Assets

First you need to pass the asset manager to a view, you can do that my doing the following in your controller:

Then just tell the manager what asset type to output and from what container: