Welcome Guest, Not a member yet? Register   Sign In
Views renderer merging template & content

In CI3, i was using  load->view() with "true" parameter to merge template and body content

$data['body'] = $this->load->view('ecriture/index', $data, true);
$this->load->view('template', $data);

assuming that template.php contains some <?=$body?>

With CI4 I try to use view renderer,
is this the better way to manage views the same way as i exposed above

$parser = \Config\Services::parser();
$view = \Config\Services::renderer();

echo $view->render('templates/header');
echo $parser->setData($data)->render('ecriture/index');
echo $view->render('templates/footer');

looking at Docs » CodeIgniter4 User Guide
chapter Docs » Building Responses » View Parser
it is written "...to load the parser class is through its service:"
$parser = new \CodeIgniter\View\Parser();
but this leads to : ArgumentCountError
Too few arguments to function CodeIgniter\View\Parser::__construct()

instead :
$parser = \Config\Services::parser();
works well

And so does :
$parser = new \CodeIgniter\View\Parser(NULL);
don't you think user guide might mention it ?

Thanks !

Messages In This Thread
Views renderer merging template & content - by foxbille - 03-06-2020, 07:03 AM

Theme © iAndrew 2016 - Forum software by © MyBB