kriswallsmith / assetic

Asset Management for PHP
MIT License
3.76k stars 559 forks source link

Assetic with twig #862

Open nimasdj opened 6 years ago

nimasdj commented 6 years ago

I want to use Assetic with standalone Twig but I am a bit confused. I use code below and it works fine when I echo it but in standalone twig when I have {% stylesheets 'css/*' debug=true %} ... {% stylesheets %} I get Error 0: Unexpected token "end of template" of value "" ("end of statement block" expected). What wrong I did?

use Assetic\AssetManager;
use Assetic\Asset\FileAsset;
use Assetic\Factory\AssetFactory;
use Assetic\Asset\GlobAsset;
use Assetic\Extension\Twig\AsseticExtension;
$am = new AssetManager();

$am->set('css', new GlobAsset('/css/*'));

$factory = new AssetFactory('css');
$factory->setAssetManager($am);

$js = $factory->createAsset(array(
    '@css',
));

//echo $js->dump();

$twig->addExtension(new AsseticExtension($factory));
AlexNodex commented 6 years ago

This is not a bug or an issue, it's a usability concern.

Please go to Stack overflow / IRC for help

stof commented 6 years ago

Well, you are using

{% stylesheets 'css/*' debug=true %} ... {% stylesheets %}

This opens 2 {% stylesheets %} tags. I think what you wanted is actually this:

{% stylesheets 'css/*' debug=true %} ... {% endstylesheets %}

Note that this snippet is using a {% endstylesheets %} tag for the end, not a {% stylesheets %} one.

nimasdj commented 6 years ago

Thanks @stof I corrected it, I don't get error, but I don't yet get the css from Assetic-Bundle. when I do echo $css->dump() it works fine. but how to have it in twig?

nimasdj commented 6 years ago

Any advise to this? https://stackoverflow.com/questions/47098705/how-to-use-assetic-with-twig

bejutassle commented 6 years ago

Did you find the solution?