Twig 如何在细枝中设置默认主题?
我用一根长着细枝的丝线 我创建自定义表单分区布局并将其放在webroot中(例如) 我是这样注册TwigService提供者的Twig 如何在细枝中设置默认主题?,twig,silex,Twig,Silex,我用一根长着细枝的丝线 我创建自定义表单分区布局并将其放在webroot中(例如) 我是这样注册TwigService提供者的 $app->register(new Silex\Provider\TwigServiceProvider(), array( 'twig.path' => __DIR__ . '/../views', 'twig.options' => array( 'cache' => __DIR__ . '/../c
$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']
));
但我有一个错误
Twig\u Error\u Loader:Template“/home/versh/sale/web/form\u div\u layout.Twig”未在第52行的“layout.Twig”中定义()
如何正确注册主题?
我知道,如果我将主题放在twig.path中,它会起作用,但这不是解决方案,我将twig与名称空间一起使用,我认为这是最灵活的做法:
$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());
您可以根据需要定义任意多个名称空间。您还必须将基本模板form\u div\u layout.html.twig
添加到twig.form.templates
选项
$app->register(新的Silex\Provider\TwigServiceProvider(),数组(
'twig.path'=>\uuuuu DIR\uuuuu./../views',
'twig.options'=>数组(
'cache'=>\uuuu DIR\uuuu./../cache',
),
'twig.form.templates'=>数组(
'form_div_layout.html.twig',
'主题/窗体分区布局.twig'
),
));