私は silex ベースのサイト用にこの twig 拡張機能を持っています:
<?php
namespace UT\Provider;
/**
* Twig extension for containing any additional twig functions we need
*/
class TwigUTProvider extends \Twig_Extension {
public function getName() {
return 'ut_functions';
}
public function getFunctions() {
return [
new \Twig_SimpleFunction("maybeDecodeJapanse", [$this, \UT\Provider\TwigUTProvider::maybeDecodeJapanse()]),
];
}
public function maybeDecodeJapanse() {
return 'a string';
}
}
次のようにアプリケーションファイルに登録されています。
$this->register(new Provider\TwigServiceProvider, [
'twig.path' => [
__DIR__ . '/Resources/Templates',
$this['docroot'] . '/silex/vendor/braincrafted/bootstrap-bundle/Braincrafted/Bundle/BootstrapBundle/Resources/views/Form',
__DIR__ . '/../Floso/Templates',
],
'twig.options' => [
'auto_reload' => true,
'cache' => $this['debug_mode'] ? false : ($this['docroot'] . '/silex/var/cache/twig'),
'debug' => $this['debug_mode'],
],
]);
# Add Twig extensions
$this['twig'] = $this->share($this->extend('twig', function ($twig) {
$twig->addExtension(new \UT\Provider\TwigUTProvider());
$twig->addExtension(new BootstrapBundle\Twig\BootstrapIconExtension('glyphicon'));
$twig->addExtension(new BootstrapBundle\Twig\BootstrapLabelExtension);
$twig->addExtension(new BootstrapBundle\Twig\BootstrapBadgeExtension);
$twig->addExtension(new BootstrapBundle\Twig\BootstrapFormExtension);
$twig->addExtension(new \Twig_Extension_StringLoader());
$twig->getExtension('core')->setTimezone('Europe/London');
return $twig;
}));
これは正しいようです-拡張クラス名にスペルミスを導入すると、私が立ち往生しているものとは異なる例外が発生します。
私は小枝テンプレートでこの拡張機能を で呼び出します{{ maybeDecodeJapanese() }}
。これにより、この例外が発生します (テンプレート呼び出し自体が原因ではないようです。スペルミスにより、標準関数が見つからないという例外が生成されます)。
Class '__TwigTemplate_3318c38dfd9c3eb0c4193184a517ff94fdd975ffb45d7f0a8f7490718f3bc1ef' not found
これは /silex/vendor/twig/twig/lib/Twig/Environment.php で発生します
私の最善の推測では、これはある種のキャッシュ ファイルです。開発環境ではキャッシュが無効になっていますが、とにかくキャッシュフォルダーの内容を削除しようとしましたが、役に立ちませんでした。グーグルはまだ他のリードを提供していません。
問題の原因を特定するためのヘルプは非常に役立ちます。