• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Views renderer merging template & content

#1
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
Reply

#2
@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
Reply

#3
(03-06-2020, 07:15 AM)John_Betong Wrote: @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
Thanks,
but i meant, here -> https://codeigniter4.github.io/userguide...rser-class
Reply

#4
(03-06-2020, 02:14 PM)foxbille Wrote:
(03-06-2020, 07:15 AM)John_Betong Wrote: @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
Thanks,
but i meant, here -> https://codeigniter4.github.io/userguide...rser-class


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.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.