include view in parser |
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!
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/CodeIgnit...=view#view PHP Code: <?= view('viewfile', ...) ?>
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. (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 (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')
Ah, so you are using new templating engine? https://codeigniter4.github.io/CodeIgnit...arser.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. (01-09-2019, 01:34 AM)Pertti Wrote: Ah, so you are using new templating engine? https://codeigniter4.github.io/CodeIgnit...arser.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 ![]()
Good call. Can't believe we overlooked that one! I'll add it to the to do list.
(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. |
Welcome Guest, Not a member yet? Register Sign In |