assetic
assetic copied to clipboard
[support] AssetReference HELP !
I'm using Silex with twig and assetic.
Can somebody tell me how to add an asset reference for something like
{% javascripts '@plugin' filter='yui_js' output="js/plugin" %}
<script src="{{ asset(asset_url) }}"></script>
{% endjavascripts %}
I've tried to follow the doc but I was never able to actually render the twig template...
I've added a couple of code lines to dump it via a command but that's all.
That's the doc:
use Assetic\Asset\AssetCollection;
use Assetic\Asset\AssetReference;
use Assetic\Asset\FileAsset;
$am->set('my_plugin', new AssetCollection(array(
new AssetReference($am, 'jquery'),
new FileAsset('/path/to/jquery.plugin.js'),
)));
But in fact I don't understand why I have to declare the assets since there is a Twig formulae loader:
use Assetic\AssetWriter;
use Assetic\Extension\Twig\TwigFormulaLoader;
use Assetic\Extension\Twig\TwigResource;
use Assetic\Factory\LazyAssetManager;
$am = new LazyAssetManager($factory);
// enable loading assets from twig templates
$am->setLoader('twig', new TwigFormulaLoader($twig));
// loop through all your templates
foreach ($templates as $template) {
$resource = new TwigResource($twigLoader, $template);
$am->addResource($resource, 'twig');
}
$writer = new AssetWriter('/path/to/web');
$writer->writeManagerAssets($am);
I'm working on https://github.com/quazardous/silex-pack