| 1 |
Building and Dumping Assets |
| 2 |
--------------------------- |
| 3 |
|
| 4 |
The is the simplest approach to using Assetic. It involves two steps: |
| 5 |
|
| 6 |
1. Create a PHP script in your web directory that uses the Assetic OOP API to |
| 7 |
create and output an asset. |
| 8 |
2. Reference that file from your template. |
| 9 |
|
| 10 |
For example, you could create a file in your web directory at |
| 11 |
`assets/javascripts.php` with the following code: |
| 12 |
|
| 13 |
use Assetic\Asset\AssetCollection; |
| 14 |
use Assetic\Asset\FileAsset; |
| 15 |
use Assetic\Filter\Yui\JsCompressorFilter as YuiCompressorFilter; |
| 16 |
|
| 17 |
$js = new AssetCollection(array( |
| 18 |
new FileAsset(__DIR__.'/jquery.js'), |
| 19 |
new FileAsset(__DIR__.'/application.js'), |
| 20 |
), array( |
| 21 |
new YuiCompressorFilter('/path/to/yuicompressor.jar'), |
| 22 |
)); |
| 23 |
|
| 24 |
header('Content-Type: application/js'); |
| 25 |
echo $js->dump(); |
| 26 |
|
| 27 |
In your HTML template you would include this generated Javascript using a |
| 28 |
simple `<script>` tag: |
| 29 |
|
| 30 |
<script src="/assets/javascripts.php"></script> |
| 31 |
|
| 32 |
Next: [](concepts.mdBasic Concepts](concepts.md](concepts.md) |
| 33 |
|