私は以下のように拡張する1つのクラスを持ってい\Twig_Extension
ます:
class MYTwigExtension extends \Twig_Extension
{
protected $doctrine;
protected $router;
public function __construct(RegistryInterface $doctrine , $router)
{
$this->doctrine = $doctrine;
$this->router = $router;
}
public function auth_links($user , $request)
{
// Some other codes here ...
// HOW TO GENERATE $iconlink which is like '/path/to/an/image'
$html .= "<img src=\"$iconlink\" alt=\"\" /> ";
echo $html;
}
}
私の質問は、Twig Extension でアセット リンクを生成する方法です。クラスで ASSET ヘルパーの代わりが欲しいです。基本的に、ここで何を注入または使用する必要があるかわかりません! 前もって感謝します。
<img src="{{ asset('img/icons/modules/timesheet.png') }}" alt="" />