2013-12-09 2 views
3

나는 나뭇 가지와 함께 silex를 사용합니다. 나뭇 가지에 기본 테마를 설정하는 방법은 무엇입니까?

나는 form_div_layout 사용자 정의 을 만들고 난이

$app->register(new Silex\Provider\TwigServiceProvider(), array(
    'twig.path' => __DIR__ . '/../views', 
    'twig.options' => array(
     'cache' => __DIR__ . '/../cache/twig', 
     'strict_variables' => false 
    ), 
    'twig.form.templates'=> [WEBROOT . '/form_div_layout.twig'] 
)); 

같은 TwigService 공급자를 등록 (예를 들어) 웹 루트에

를 넣어하지만 난 방법을 오류 Twig_Error_Loader: Template "/home/versh/sale/web/form_div_layout.twig" is not defined() in "layout.twig" at line 52.

에게 있습니다 테마를 올바르게 등록 하시겠습니까? 나는 내가 twig.path에 테마를 넣어 경우가 작동합니다 알고 있지만,이 솔루션

답변

6
내가 네임 스페이스와 나뭇 가지를 사용하고

아니고, 나는 그것이 가장 유연한 방법입니다 생각 :

$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.options' => array(
    'cache' => true, 
    'strict_variables' => true, 
    'debug' => false, 
    'autoescape' => true 
    ) 
)); 

// set namespace for your application 
$app['twig.loader.filesystem']->addPath(WHERE_EVER_YOU_WANT_PATH, 'yourApplication'); 

이제 네임 스페이스를 사용하여 템플릿을 렌더링 할 수 있습니다 : 당신이 필요로

return $app['twig']->render('@yourApplication/sample.twig', array()); 

당신이 많은 네임 스페이스를 정의 할 수 있습니다.

4

기본 템플릿 form_div_layout.html.twig ~ twig.form.templates 옵션도 추가해야합니다.

$app->register(new Silex\Provider\TwigServiceProvider(), array(
    'twig.path' => __DIR__.'/../views', 
    'twig.options'=>array(
     'cache'  => __DIR__.'/../cache', 
    ), 
    'twig.form.templates' => array(
     'form_div_layout.html.twig', 
     'theme/form_div_layout.twig' 
    ), 
)); 
관련 문제