Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assetic with twig #862

Open
nimasdj opened this issue Nov 3, 2017 · 5 comments
Open

Assetic with twig #862

nimasdj opened this issue Nov 3, 2017 · 5 comments

Comments

@nimasdj
Copy link

nimasdj commented Nov 3, 2017

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
Copy link

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

Please go to Stack overflow / IRC for help

@stof
Copy link
Collaborator

stof commented Nov 3, 2017

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
Copy link
Author

nimasdj commented Nov 3, 2017

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
Copy link
Author

nimasdj commented Nov 3, 2017

@bejutassle
Copy link

Did you find the solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants