I’m writing a (Symfony2) SmartyBundle extension to support Assetic.
To support the stylesheets feature I’ve registered a block plugin called stylesheets:
{stylesheets
assets='@SmartyBundle/Resources/public/css/*'
debug=true}
<a href="{$asset_url}">{$asset_url}</a>
{/stylesheets}
This plugin gets called properly and everything work as expected when the Symfony/assetic cache is created.
The problem arises When the Symfony cache is empty and Assetic loads every template file resource and asks the template engine to retrieve a PHP array with the tokens found in the stylesheets tag. The class called to retrieve the array is SmartyFormulaLoader.
<?php
class SmartyFormulaLoader implements \Assetic\Factory\Loader\FormulaLoaderInterface
{
public function load(ResourceInterface $resource)
{
// raw template content
$content = $resource->getContent();
// a FileLoaderImportCircularReferenceException is throw here
$smartyParsed = $this->smarty->fetch('string: '.$content);
// build an array with tokens extracted from the block function
$formulae = $this->extractStylesheetsTokens($smartyParsed);
return $formulae;
}
When $smarty->fetch() is called in the load() method an exception is thrown: Symfony\Component\Config\Exception\FileLoaderImportCircularReferenceException: Circular reference detected in "." ("." > ".").
This is caused by the Smarty template being parsed/compiled and the stylesheets plugin being called again.
So I’m asking if Smarty provides a template parser that extracts the block function tokens (without calling the stylesheets plugin) so I can feed Assetic. Or any other solution that I may be missing to solve this.
Thanks.
After a little chat with Smarty dev @rodneyrehm we came to the conclusion that:
So, for this particular case we came up with this implementation:
Full implementation is available here: https://github.com/noiselabs/SmartyBundle/blob/master/Assetic/SmartyFormulaLoader.php