我正在编写一个 (Symfony2) SmartyBundle扩展来支持Assetic。
为了支持样式表功能,我注册了一个名为的块插件stylesheets
:
{stylesheets
assets='@SmartyBundle/Resources/public/css/*'
debug=true}
<a href="{$asset_url}">{$asset_url}</a>
{/stylesheets}
当 Symfony/assetic 缓存被创建时,这个插件被正确调用并且一切都按预期工作。
当 Symfony 缓存为空并且 Assetic 加载每个模板文件资源并要求模板引擎检索带有在样式表标签中找到的标记的 PHP 数组时,就会出现问题。调用来检索数组的类是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;
}
在方法$smarty->fetch()
中调用时load()
抛出异常:Symfony\Component\Config\Exception\FileLoaderImportCircularReferenceException: Circular reference detected in "." ("." > ".")
.
这是由于 Smarty 模板被解析/编译和stylesheets
插件被再次调用造成的。
所以我问 Smarty 是否提供了一个模板解析器来提取块函数标记(不调用样式表插件),这样我就可以提供 Assetic。或者我可能缺少的任何其他解决方案来解决这个问题。
谢谢。