How to use LayoutView with parser? |
Hi guys
![]() I looked everywhere but I still haven't found ways to use the layout system when I render my pages through Parser ... The pages created by the parser simply ignore the php codes responsible for using ViewLayout ... Example: Code: echo $this->parser->setData($data)->render('website/pages/indexPage'); not work: Code: <?php $this->renderSection('css') ?> not work: Code: { $this->renderSection('css') } Does anyone know how I can use them together? ![]()
I do not think it will work because they are two different entities.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
This really important feature. I'll want use LayoutView with parser cuz uncomfortable use native php code.
The View Parser:
Using the Parser, in your view templates are processed only by the Parser itself, and not like a conventional view PHP script. PHP code in such a script is ignored by the parser, and only substitutions are performed. This is purposeful: view files with no PHP. So maybe it would work if you ran the Parser on the Layout using: PHP Code: $parser = \Config\Services::parser(); I do not have the time to play with this but you may like to give it a try. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(08-16-2020, 08:17 AM)InsiteFX Wrote: The View Parser: Unfortunately it doesn't. And this impossibility is really demotivating ... It seems very obvious that both features can work together as it is in Laravel ...
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') ?> 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.
It will works if you add comments to the view
create parser and return it inside a view Code: $parser = Services::parser(); and for the view like this add html layout below the comment Code: {#
i'm using this trick.
$view = view ('partial/partOne); $viee .= view('partial/partTwo'); .. echo $parser->setData($data)->render($view);
you should create layout file: layout.php
Code: <?=view('app/view/header'); ?> file to view when call from route : content.php Code: <?= $this->extend('app/view/layout) ?> controller (example): Code: function your_function(){ |
Welcome Guest, Not a member yet? Register Sign In |