Welcome Guest, Not a member yet? Register   Sign In
How to use LayoutView with parser?
#7

It should work.

To do this, you will have one PHP file containing the layout (the 'layout' file), another one that is supplied as an argument to the call to view() (the 'view' file), and then a third one that is supplied as an argument to the call to the parser's render() function (the 'parser' file).

You first obtain the string returned from the call to the parser->render(). This will be plain html, but should be missing whatever the layout provides. You need to create your parser file with this in mind.  You don't immediately echo this string out, but instead provide it as input data to your call to the view() function.  You can put this string into a single variable, and then echo it out inside of the view file.

So your view file will look something like this:
Code:
<?= $this->extend('\layouts\my_layout_file') ?>

<?= $this->section('content') ?>
<?= $body ?>
<?= $this->endSection() ?>

And then your controller is going to have a sequence something like:
$parser = \Config\Services::parser();
$parser_data = ['parser_data' => [...]];
$parser_text = $parser->setData($parser_data)->render('parser_file');
return view('view_file', ['body'=>$parser_text]);

within your view_file, you will just put <?= $body ?> within the layout section.
Reply


Messages In This Thread
How to use LayoutView with parser? - by aleckyann - 08-14-2020, 10:40 AM
RE: How to use LayoutView with parser? - by glarson - 04-16-2021, 09:34 AM



Theme © iAndrew 2016 - Forum software by © MyBB