Question

I'm trying to use Assetic paired with Twig without actually using Symfony. I have the following setup for the twig and assetic:

     /**
     * @param string $templateBaseDir Path to templates
     * @param string $cacheBaseDir Path to compilation cache
     */
    public function setupTwig($templateBaseDir, $cacheBaseDir)
    {
        $loader = new Twig_Loader_Filesystem($templateBaseDir);
        $this->twig = new Twig_Environment(
            $loader, array( /*'cache' => $cacheBaseDir,*/)
        );


        $factory = new AssetFactory(__DIR__ . '/../../Resources/public/');
        $factory->setDebug(true);

        $fm = new FilterManager();
        $fm->set('lessphp', new LessphpFilter());
        $fm->set('rewrite', new CssRewriteFilter());
        $factory->setFilterManager($fm);

        $this->twig->addExtension(new AsseticExtension($factory));
        $this->twig->addExtension(new Twig_Extension_Debug());

        $am = new LazyAssetManager($factory);
        $factory->setAssetManager($am);
        $am->setLoader('twig', new TwigFormulaLoader($this->twig));
        $am->addResource(new DirectoryResource(__DIR__ . '/../../Resources/views/'),'twig');

        $writer = new AssetWriter(__DIR__ . '/../../../../../../web');
        $writer->writeManagerAssets($am);

        $this->assetic = $factory;
    }

This effectively generates all requested files from twig extensions but

{% stylesheets 'css/jquery-ui.css' %}
<LINK rel=stylesheet type=text/css href="{{ asset_url }}" media=all>
{% endstylesheets %}

Produces

<LINK rel=stylesheet type=text/css href="css/e9a2fc7_jquery-ui_1.css" media=all>

While the actual generated file is named css/e9a2fc7.css

How can I make these names match?

Was it helpful?

Solution

I've investigated the source code of Assetic. This behavior if for debugging combined scripts and stylesheets. Moving Assetic to non-debug mode makes the code works as expected.

So it is neccessary to use combine=false each time instead of debug mode.

I don't know why Assetic makes debug files unaccessible from the web (generates one name and produce another).

I'll try to post a bug later.

UPD. combine=false does not work, because even it is set Assetic produses combined files when dumping and requests files with fileparts (like css/ae13694_data_tables_1.css instead css/ae13694.css).

To the history - I've filed a bug for it long ago https://github.com/kriswallsmith/assetic/issues/613

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top