include view in parser - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29) +--- Thread: include view in parser (/showthread.php?tid=72515) |
include view in parser - adnzaki - 01-01-2019 Hi, I'm so excited with brand new template parser in CI4. But I got a problem when including file directly in template, because in CI3 I used to use this simple code to include view inside a view Code: $this->view() The question, is there a way in parser for including view directly? If not, it would be great if CI4's parser comes with functionality to include file directly (nested view). And here is plugin I added to parser: PHP Code: public static function include(array $params = []) Thanks CI4 team! RE: include view in parser - Pertti - 01-02-2019 I have to admit I have not personally played with v4 yet, but I think this might be what you are after: https://codeigniter4.github.io/CodeIgniter4/general/common_functions.html?highlight=view#view PHP Code: <?= view('viewfile', ...) ?> RE: include view in parser - puschie - 01-02-2019 you could also use your view as variable replacement PHP Code: $template = "Hello, {var1} {firstName} {lastName}"; makes it much easier to see dependencies and no view nesting. RE: include view in parser - adnzaki - 01-08-2019 (01-02-2019, 02:00 AM)Pertti Wrote: I have to admit I have not personally played with v4 yet, but I think this might be what you are after: Unfortunately, we couldn't place any PHP code inside the template. that's why I created additional plugin for including template inside a template RE: include view in parser - adnzaki - 01-08-2019 (01-02-2019, 05:09 AM)puschie Wrote: you could also use your view as variable replacement I had tried that way but the parser could't load the view as expected. The other way, I added 'raw' in the second argument Code: setData($data, 'raw') RE: include view in parser - Pertti - 01-09-2019 Ah, so you are using new templating engine? https://codeigniter4.github.io/CodeIgniter4/outgoing/view_parser.html I guess it depends on what kind of PHP code you want to put in your view file, but it probably shouldn't do anything beyond IF checks, which you can do in templating engine: Code: {if $role=='admin'} You should do everything else on Controller or Model side, so view itself shouldn't try to go and figure things out, it should be just - here's data to render, here#s maybe slightly different layout or styling if some conditions are met. RE: include view in parser - adnzaki - 01-09-2019 (01-09-2019, 01:34 AM)Pertti Wrote: Ah, so you are using new templating engine? https://codeigniter4.github.io/CodeIgniter4/outgoing/view_parser.htmlOk thanks, but I guess I will use my own plugin to include template inside a template. It replaced old code like PHP Code: <?php $this->view('viewfile) ?> with {+ include Path\To\template +} And it works well RE: include view in parser - kilishan - 04-23-2019 Good call. Can't believe we overlooked that one! I'll add it to the to do list. RE: include view in parser - adnzaki - 04-20-2020 (04-23-2019, 06:39 AM)kilishan Wrote: Good call. Can't believe we overlooked that one! I'll add it to the to do list.Whoops, I missed my own thread for a long time. Actually I got that idea from CodeIgniter4 official user guide, and implemented in my own project. I have tried that additional plugin in HMVC style (like I'm doing in my project) and it works very well. |