The asset manager holds containers for you JS and CSS assets.
The easiest way to use the Asset Manager is to make sure your Controllers extend
Tomahawk\Routing\Controller. You then have access to it through
Other wise just add the following parameter to the construct method of your
Tomahawk\Asset\AssetManagerInterface and it will get injected in through the Service Container.
Asset containers are great for grouping assets under a particular group or section, e.g header and footer JS.
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:
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: