====== 01 twigについて ====== Symfony2 のテンプレートエンジンである Twig {{ ... }} : 変数や式の結果を出力します。| {% ... %} : テンプレートのロジックを制御するタグで、たとえば for ループや if 文を記述します。| テンプレートへのパス $app->register(new Silex\Provider\TwigServiceProvider(), array( 'twig.path' => __DIR__ . '/views', )); レンダリング $app->get('/test', function() use($app) { $variables['test1'] = 'これはテストです。'; $variables['test2'] = array('テスト1', 'テスト2', 'テスト3'); return $app['twig']->render('test.html.twig', $variables); }); [[http://fivestar.hatenablog.com/entry/2011/12/21/013929|twigパラメータ]] [[http://api.symfony.com/master/Symfony/Component/HttpFoundation/Request.html Symfony2 requestクラスのMethod]] ===== Symfony Twigでシングルクォーテーションをコードに書き出す方法 ===== twigではXSS対策で、htmlspecialcharsでENT_QUOTESが付いてる autoescapeをfalseにしてあげれば、OFFにもできる。 $app->register(new Silex\Provider\TwigServiceProvider(), array( 'twig.path' => __DIR__ . '/views', 'twig.options' => array( 'autoescape' => false, ), ));