Open jmcclell opened 11 years ago
$twigLoader
should be your Twig_Loader object
Hi, I have this setup. The asset_url
is being generated correctly, but the files are not being dumped. What am I missing!
$loader = new \Twig_Loader_Filesystem($paths);
$twig = new \Twig_Environment($loader, array(
'cache' => $app.'/themes/cache'
));
//asset factory
$assetFactory = new AssetFactory($app."/themes/".$theme );
$assetFactory->setDebug($this->container->getParameter('kernel.debug'));
$assetFactory->setAssetManager(new AssetManager());
$assetFactory->setFilterManager(new FilterManager());
$am = new LazyAssetManager($assetFactory);
$am->setLoader('twig', new TwigFormulaLoader($twig));
$finder = new Finder();
$finder
->files()
->in($app."/themes/".$theme)
->exclude('css')
->exclude('js')
->exclude('images')
->name("*twig")
;
foreach($finder as $template){
$resource = new TwigResource($loader, $template);
$am->addResource($resource, 'twig');
}
$writer = new AssetWriter($app.'../web');
$writer->writeManagerAssets($am);
$twig->addExtension(new AsseticExtension($assetFactory));
Okay, I got it working.
It was the $template
, which was not string. I got it working by changing $resource = new TwigResource($loader, $template);
to $resource = new TwigResource($loader, $template->getFileName());
But debug
mode is not being considered here. I have 2 stylesheets in the stylesheets
tag, the links are being generated correctly, but only 1 file is being generated!!
{% stylesheets
'css/bootstrap.css'
'css/shop-homepage.css'
%}
<link href="themes/{{ asset_url }}" rel="stylesheet">
{% endstylesheets %}
<link href="themes/css/706c876_bootstrap_1.css" rel="stylesheet">
<link href="themes/css/706c876_shop-homepage_2.css" rel="stylesheet">
But I have only 1 file 706c876.css
generated
+1 for adding more details in the Twig Part of the documentation.
If anyone want to set Assetic and Silex . This is how you could do it
$resource = new TwigResource($app[twig.loader], 'relative/path/to/template/file');
The current documentation for the Twig based dump script is hard (if not impossible) to follow. See PHP comments below:
Could you please clarify the documentation in regards to Twig? It would be extremely helpful.