0
我有一个旧的项目我正在使用修身版2到3修身2渲染直接HTML
我试图树枝融入苗条2 ,同时也保持了旧我不能升级默认slim2渲染器。
目前我有这个。
class TwigView extends \Slim\View
{
public function rendertwig($template,$data = array()){
global $twig;
$twigResults = $twig->render($template,array('test' => '1'));
$data = array_merge($this->data->all(), $data);
return $this->render($twigResults, $data);
}
}
$view = new TwigView();
$config['view'] = $view; //@JA - This command overides the default render method.
//@JA - Intialize Slim
$app = new \Slim\Slim($config);
的想法是,我所说的这句话$app->view->rendertwig('file.twig')
当我需要渲染的树枝模板和使用$app->render('template.php')
为所有使用模板的默认slim2方法的其他模板。
但是,我得到一个错误,因为在我的rendertwig函数$ this-> render()函数中需要第一个参数的模板名称。 有没有一种方法可以将树枝结果直接渲染到超薄引擎而不需要模板文件?
我知道这是不好的形式有两种模板引擎,但最终我将切换一切嫩枝但我需要这是一个临时解决方案,直到我能修补所做的一切。
当我检查slim的视图对象时,它将它定义为其渲染方法,它将解释问题。
protected function render($template, $data = null)
{
$templatePathname = $this->getTemplatePathname($template);
if (!is_file($templatePathname)) {
throw new \RuntimeException("View cannot render `$template` because the template does not exist");
}
$data = array_merge($this->data->all(), (array) $data);
extract($data);
ob_start();
require $templatePathname;
return ob_get_clean();
}