Twig テンプレート エンジンでテンプレートの保存場所に関連するパスを使用する方法があるかどうか疑問に思っています。
シナリオは次のとおりです。
アプリケーションが fileadmin/myApplication にある Typo3 Web サイトがあります。テンプレート エンジンとして Twig を使用して、JSON ファイルから動的に読み込まれる多言語コンテンツをレンダリングしています。私のテンプレート ファイルのいくつかには、Typo3 の性質上、fileadmin/myApplication/img/... の src-path が必要な画像へのパスが含まれています。
ここで、アプリケーションの新しいバージョンをテストする場合、テンプレート ファイル内のイメージへのパスを変更せずに、ディレクトリ fileadmin/myApplication2.0 を作成できるようにしたいと考えています。
相対パスをサーバー ファイル パスに変換するテンプレート エンジン (raintpl など、このリンクを参照) があります。Twigで同じ効果を達成する簡単な方法はありますか?
例えば
templates/template.html
img/logo.png
出力
<img src="fileadmin/myApplication2.0/img/logo.png">
これは、rain.tpl が行う方法です。
WYSIWYG - Path replace
This cool feature allows designers to create templates as regular HTML with images and styles with relative paths, RainTPL replaces automatically these paths with the correct server paths.
Absolute paths and paths ending with # will be not changed.
<link href="style.css" type="text/css" rel="stylesheet">
<img src="img/logo.gif">
Output html:
<link href="tpl/style.css" type="text/css" rel="stylesheet">
<img src="tpl/img/logo.gif">
Note: if you set raintpl::$base_url, RainTPL will replace the path with raintpl::$base_url.