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 ! Eric
@foxbill,
> Too few arguments to function CodeIgniter\View\Parser::__construct() > don't you think user guide might mention it ? Yes it does: https://codeigniter4.github.io/userguide...=view#view (03-06-2020, 07:15 AM)John_Betong Wrote: @foxbill,Thanks, but i meant, here -> https://codeigniter4.github.io/userguide...rser-class
(03-06-2020, 02:14 PM)foxbille Wrote:(03-06-2020, 07:15 AM)John_Betong Wrote: @foxbill,Thanks, If you look at the documentation it doesn't say to pass anything to the parser() class when instantiating yet we get an error if we don't. This needs to be updated I image. |
Welcome Guest, Not a member yet? Register Sign In |